Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Jan 2013
    Location
    Ranchi
    Posts
    206

    What is the main difference between var and let in JavaScript?

    What is the main difference between var and let in JavaScript?

  2. #2
    Member
    Join Date
    Nov 2017
    Posts
    37
    The difference is scoping. var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block.

    Also, variables declared with let are not accessible before they are declared in their enclosing block. As seen in the demo, this will throw a ReferenceError exception.
    Check out our new Online Email Validator @ Zero Bounce
    Our unique email validation service eliminates high bounce rates.

  3. #3
    Registered User
    Join Date
    Sep 2017
    Location
    ghaziabad
    Posts
    280
    VAR- the JavaScript variables statement are used to declare the variable and we can initialize the value of that variable.

    LET- this refers to the local variable in a block scope. It is also similar to var and we can optionally initialize the variable.

  4. #4
    Registered User
    Join Date
    Feb 2014
    Location
    delhi
    Posts
    515
    Scoping makes the difference. var's scope is function level but let is scoped in its enclosing block, that is ({}).

  5. #5
    Registered User
    Join Date
    Sep 2017
    Posts
    955
    Var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  Find Web Hosting      
  Shared Web Hosting UNIX & Linux Web Hosting Windows Web Hosting Adult Web Hosting
  ASP ASP.NET Web Hosting Reseller Web Hosting VPS Web Hosting Managed Web Hosting
  Cloud Web Hosting Dedicated Server E-commerce Web Hosting Cheap Web Hosting


Premium Partners:


Visit forums.thewebhostbiz.com: to discuss the web hosting business, buy and sell websites and domain names, and discuss current web hosting tools and software.