Загрузка...

What is the scope of variables in JavaScript? | Block scope

What is the scope of variables in JavaScript?

#scope in #javascript is the area where we have valid access to #variables or functions.

#Global scope: The default scope for all code running in script mode.
Module scope: The scope for code running in module mode.
Function scope: The scope created with a function.

In addition, variables declared with let or const can belong to an additional scope:

Block scope: The scope created with a pair of curly braces (a block).

#example
{
var x = 1
let y = 1
const z = 1
}
console.log(x)
console.log(y)
console.log(z)
Scopes can be nested : An interesting property of scopes is that they can be nested.

Lexical scope: "The lexical scope consists of outer scopes determined statically."

Видео What is the scope of variables in JavaScript? | Block scope канала Codelys Learning
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять