
Modern JS Discussion: var/let/const
This article was originally published on bmf-tech.com . ※This article is a reprint from the Innovator Japan Engineers’ Blog . What is Scope Before diving into the main topic, let's review the definition of scope. Scope refers to the range within which variable names and function names can be referenced . There are various types of scopes, but here we will explain mainly three types of scopes in a table. Scope Name Range Remarks Global Outside of functions Accessible from anywhere. Local (Function) Inside of functions Accessible only from within the local scope. Block Inside of blocks ({ }) if, for, switch, etc. Block scope was not originally available in JavaScript, but with the introduction of let and const, block scope can now be used. About var, let, const var Redeclaration Reassignment Scope ○ ○ Local var allows both redeclaration and reassignment. var a = 1 ; var a = 2 ; // Redeclaration possible function sayNum () { a = 100 ; // Reassignment possible return a ; } console . log (
Continue reading on Dev.to JavaScript
Opens in a new tab


