Programming Hub

Friday, July 3, 2020

Javascript Var and Let for loop Interview question


var:

Here var keyword has local scope and printing 11 after for loop.

for( var i=0; i<=10; i++)
{
console.log(i)
}
console.log(i)


Let

let keyword has blocked scope. Hence it gave error in below code

for( let j=0; j<=10; j++)
{
console.log(j)
}
console.log(j)


Posted by pkmarathe at 4:43 AM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: javascript

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2021 (5)
    • ►  November (5)
  • ▼  2020 (68)
    • ▼  July (18)
      • Four Different Way to Find nth Highest Salary in S...
      • SQL Server Gender Swap Query
      • Abstract Factory Pattern
      • Factory Method Design Pattern - C#
      • Tuple in C#
      • Anonymous Method in C#
      • Partial Classes in C#
      • Partial Methods in C#
      • Content Negotiation in Web API
      • Difference between SOAP And REST APIs
      • JSON and XML Serialization in ASP.NET Web API
      • Action Results in Web API 2
      • Variable scopes in JavaScript
      • The Difference Between Regular Functions and Arrow...
      • What is lexical scope in Javascript?
      • Javascript Var and Let for loop Interview question
      • JavaScript Use Strict
      • JavaScript Hoisting
    • ►  May (5)
    • ►  April (45)
Picture Window theme. Powered by Blogger.