minhluuquang / TIL

You are seeing a part of my brain
0 stars 0 forks source link

Scope in js #2

Open minhluuquang opened 6 years ago

minhluuquang commented 6 years ago

An important difference between JavaScript and other languages like Java is that in JavaScript, blocks do not have scope; only functions have a scope. So if a variable is defined using var in a compound statement (for example inside an if control structure), it will be visible to the entire function. However, starting with ECMAScript 2015, let and const declarations allow you to create block-scoped variables.