DEV Community

Cover image for Let
Rakshambika
Rakshambika

Posted on Edited on

Let

let is a keyword used to declare variables in JavaScript.

Let:

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

  • Variables declared with let have Block Scope.

  • Using let, we can declare the variable and initialize it later.

<script>
        let a;
</script>
Enter fullscreen mode Exit fullscreen mode
  • But, declare the value before using that variable. Otherwise it show Undefined.

What is Undefined?

undefined is a special value in JavaScript that means a variable has been declared, but no value has been assigned to it yet.

<script>
        let a;
        console.log(a);
    </script>

Enter fullscreen mode Exit fullscreen mode

Output:

Undefined
Enter fullscreen mode Exit fullscreen mode

Re-initializing a value for let variable is possible.

<script>
        let a;
        a="Raksha";
        a="Raji";
        console.log(a);
 </script>
Enter fullscreen mode Exit fullscreen mode

Re-Declaring the let variable is not possible, if we try to re-declare the variable it shows the **Uncaught SyntaxError**

Error:

Excited to continue learning and building with JavaScript!

Top comments (0)