For the complete documentation index, see llms.txt. This page is also available as Markdown.

Hoisting is Dead: var vs. let vs. const

Reminder

Global variables 🤮

userName = 'Foo BAR';

console.log(userName); // Foo BAR

Use strict 😅

'use strict';

userName = 'Foo BAR'; // ReferenceError: userName is not defined
'use strict';

console.log(userName); // ReferenceError: userName is not defined

Hoisting

Variable hoisting

'use strict';

console.log(userName); // ???

var userName = 'Foo BAR';

Function hoisting

A little bit better

let

Variables are only accessible after their declaration.

Variables are only accessible in the bloc where they are declared.

const

const variables cannot be reinitialized.

Last updated