Imaginary Friend

Imaginary friend


let and const are the new keywords supported by ECMA6. Both declare block level variables. Which means variables declared as let or const are visible only within the block that they are defined in. Blocks within Javascript are generally delimited by opening and closing curling braces ({}).

Variables declared with var keyword on the other hand are global or function scoped. If you declare a new variable inside a block enclosed by curly braces, it would be visible within the nearest function scope. (The reason you are shown var i is already defined in ServiceNow script editor if you have multiple for loops). If you declare a variable as let or const inside a similar block, it won't be accessible outside of it.










Creative Commons License

Comments