let and const instead of var - Learn #ServiceNow ECMAScript 2021 #servicenowdeveloper
Hey, this is for all the ServiceNow devs
out there that are used to ECMAScript 5. If you're in a scoped application,
you are now able to use ECMAScript 2021. So if you're used to using var everywhere to declare variables,
start using let and const instead. So var is globally scoped
and can lead to confusion. So if I run this you'll see that “Hello there” runs both times,
even though this is out of scope. But if we change this over
to let and run that again, you'll see that it actually will properly error out
because we're trying to use X in the wrong scope and const means
that you don't want it to change. So you'll see I try to re-assign
that variable and it did not work. It's a good way to keep your code
clean and deliberate. Follow for more.
https://www.youtube.com/watch?v=Y_LmnYjNWYE