0

Variables: let vs var

Hi!

 

I'm new in Ninox and I am wondering about the differnce between assigning a variable using "let" statement vs using "var" statement. So far, they've both worked fine in my coding, but I would really like to know the difference and couldn't find it in the manual nor several other articles I've checked so far. Anyone who can share such wisdom, please? ('^_^)

 

Thanks in advance! ☺

 

__________________________________________________

Be prepared for the worse. You might know worse. No one knows worst until upon.

Yet, always pursue and hope for the best.

6 replies

null
    • Sean
    • 3 yrs ago
    • Reported - view

    I did some testing on the difference a while ago with explanation of the difference in JavaScript in mind. I didn't see any difference in scope between the two like there is in JavaScript. That's pretty much all I know.

    • Servicios Gastronómicos Las Maravillas
    • Johnny_MV
    • 3 yrs ago
    • Reported - view

    Oh, well... I'll just keep using them both haphazardly, then... Thx a lot, Sean! ☺

    • Ninox partner
    • RoSoft_Steven.1
    • 3 yrs ago
    • Reported - view

    Quoted from the 0001_Ninox-Reference database:

    "The 'var' statement is used to declare a variable in Ninox by assigning a value to it. It automatically assumes the data type of the assigned value. Variables are a basic element of every script and programming language. They are only temporarily valid within a script and serve to temporarily store values for further processing steps. If the script is terminated, all variables lose their contents. var" was introduced after 'let' and is documented here only for completeness. In practice, there are no noticeable differences, which is why you can stay with 'let' (or use var throughout) for consistency."

    Steven

    • Servicios Gastronómicos Las Maravillas
    • Johnny_MV
    • 3 yrs ago
    • Reported - view

    Thank you, Steven!

    If possible, I would like to get access to that database. It looks like I need an invitation to a certain team in order to get that. Would that be possible from your side? Or what do I need to get such access? (°.°)

    • Ninox partner
    • RoSoft_Steven.1
    • 3 yrs ago
    • Reported - view

    If you have a cloud subscription, I can invite you to that team, All I Need is your Email linked to Ninox.

    • jokovkilg
    • 2 yrs ago
    • Reported - view

    Variables declared by "var" keyword are scoped to the immediate function body (function scope) while "let" variables are scoped to the immediate enclosing block denoted by {....} (block scope).

    Variable declared with var keyword can be re-declared and updated in the same scope while variable declared with let keyword can be updated but not re-declared.

    Variables defined with let are hoisted to the top of the block , but not initialized. This means that the block of code is aware of the variable, but it cannot be used until it has been declared. So, using a let variable before it is declared will result in a ReferenceError.

    http://net-informations.com/q/js/let.html

Content aside

  • 2 yrs agoLast active
  • 6Replies
  • 1115Views