Results 1 to 7 of 7
  1. #1
    Senior Member
    Join Date
    Jan 2013
    Location
    Ranchi
    Posts
    205

    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
    572
    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
    1,192
    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.

  6. #6
    Registered User
    Join Date
    Apr 2014
    Location
    india
    Posts
    407
    var and let are both used for function declaration in javascript but the difference between them is that var is function scoped and let is block scoped.
    It can be said that a variable declared with var is defined throughout the program as compared to let.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    216
    Quote Originally Posted by rohit View Post
    var and let are both used for function declaration in javascript but the difference between them is that var is function scoped and let is block scoped.
    It can be said that a variable declared with var is defined throughout the program as compared to let.


    Yes, I completely agree with you.

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.