QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads JavaScript “let” Keyword

JavaScript “let” Keyword

This post is a part 1 of ECMAScript 6 Complete Tutorial post series.

“let” keyword was introduced in ES6. It lets you define block scope(bracket scope) variables in JavaScript. Initially JavaScript only supported function scope and global scope variables.

Here is an example code

if(true)
{
    let x = 12;
    alert(x); //alert's 12
}

alert(x); //x is undefined here

“let” keyword limits the variables accessibility upto a block, statement or expression.

Feb 13, 2015Narayan Prusty
Digital Signature using Web Cryptography APIJavaScript "const" Keyword
Comments: 10
  1. Ravi
    6 years ago

    is ‘let’ keyword works in IOS/ safari??

    ReplyCancel
    • raj
      6 years ago

      its also works in all browser

      ReplyCancel
  2. rajasekar
    6 years ago

    i am new one for it ..so please put .html file with example. thank you

    ReplyCancel
  3. Sulekh K
    6 years ago

    I am beginner so please guide me from initial lesson.

    ReplyCancel
  4. Juliet
    6 years ago

    great see…thanks for sharing informative news…

    ReplyCancel
  5. Nilesh
    6 years ago

    if(true)
    {
    let x = 12;
    var x = 15;
    alert(x); // then which x it will preferred var or let ?
    }

    alert(x); //x is undefined here

    what will happen if i have same variable and let name inside the block ?

    ReplyCancel
    • Dudi
      6 years ago

      OUTPUT: “12”

      Let declaration overrides the var declaration.

      ReplyCancel
    • Rajkumar K
      6 years ago

      Uncaught SyntaxError: Identifier ‘x’ has already been declared

      ReplyCancel
    • Rahul Gupta
      6 years ago

      It will throw syntax error: as x has already been declared

      ReplyCancel
    • rajasekar
      6 years ago

      if you put var x and let x inside the function .Es6 dont consider x(out will not show any value ).

      ReplyCancel

Leave a Reply Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

8 years ago 10 Comments Web Development
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • JavaScript “const” Keyword
  • JavaScript “class” Keyword
  • Javascript “use strict” Tutorial with Examples
  • JavaScript Function Techniques You May Not Know
  • Default Function Arguments Values in JavaScript
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license