![]() ![]() Let’s take a look at the following example:Īfter running this code, you’ll see the following output in the console: A block is everything inside an opening and closing curly bracket. JavaScript lacked block scope, meaning that a variable is only accessible within the block in which it’s defined. This caused a lot of frustration and unexpected behaviors for developers coming from other languages such as C, C++ or Java. Up to ES5, JavaScript had only two types of scope, function scope and global scope. This article is one of many covering new features of JavaScript introduced with ES6, including Map and WeakMap, Set and WeakSet, new methods available for String, Number, and Array, and the new syntax available for functions. They enhance JavaScript by providing a way to define block-scope variables and constants. In this tutorial, I’ll introduce let and const, two new keywords added to JavaScript with the arrival of ES6. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |