Executing that code results in the number 2 appearing twice, because the fact that the var keyword does not support block scope. Now, what do you think will appear in the console? The same thing? And it still makes sense when you consider global scope, in which a variable is declared outside of a function. Or the nearest parent function, if it's a nested function. This means that a variable would exist only within the scope of the function in which it wasĭeclared. Variables declared with the var keyword are said to be in the function scope. To begin, let's look a little closer at how variables are defined. You now have other options, and in this unit we go over why you want to use them. Identify the backtick character used to create template literals.īefore ES6, the only way you could declare a variable or a function in JavaScript was using the var keyword.Identify the new destructuring syntax used to separate data.Recognize shorthand ES6+ syntax used to initialize variables.State a reason why the const keyword should be used.Describe the difference between function and block scoping.After completing this unit, you'll be able to:
0 Comments
Leave a Reply. |