Declaration
suggest changeJavaScript provides three variable-declaration keywords: const, let, and var. Assignment to an undeclared identifier is not a declaration: it throws in strict mode and modules, and its legacy sloppy-mode behavior should never be relied upon.
constcreates a block-scoped binding that cannot be reassigned. Prefer it by default.letcreates a reassignable, block-scoped binding.varcreates a function-scoped binding and permits redeclaration. It remains important when reading legacy code or teaching hoisting, but is normally avoided in new code.
const name = 'Ada';
let count = 0;
count += 1;
const requires an initializer. It prevents reassignment of the binding, not mutation of an object stored in that binding.
const value; // SyntaxError: Missing initializer in const declaration
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents