Learn JavaScript Programming

A scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.

JS Introduction
JS Control flow
JS Functions
JS Objects
JS Types
Exceptions and Modules
JS ES6
JavaScript Asynchronous
Miscellaneous

JS let and const

In this tutorial, you will learn about JavaScript variable declaration using let and const keyword.

JS let keyword

  1. The let keyword was introduced in ES6 (2015).

  2. Variables defined with let cannot be Redeclared.

  3. Variables defined with let must be Declared before use.

  4. Variables defined with let have Block Scope.

Cannot be Redeclared

Variables defined with let cannot be redeclared.

With let you can not do this:

Block Scope

  1. Before ES6 (2015), JavaScript had only Global Scope and Function Scope.

  2. ES6 introduced two important new JavaScript keywords: let and const.

  3. These two keywords provide Block Scope in JavaScript.

  4. Variables declared inside a { } block cannot be accessed from outside the block:

Run code

JS Const keyword

  1. The const keyword was introduced in ES6 (2015).

  2. Variables defined with const cannot be Redeclared.

  3. Variables defined with const cannot be Reassigned.

  4. Variables defined with const have Block Scope as let have.

Cannot be Reassigned

Run code

When to use JavaScript const?

Always declare a variable with const when you know that the value should not be changed.

Use const when you declare:
  1. A new Array

  2. A new Object

  3. A new Function

  4. A new RegExp

Now that you know how to declare variables using var, let and const, let's learn how we can use document methods.


Share this page on :