<!-- Please press ctrl-shift-i or right-click on browser to see output in browser console window. -->
JavaScript
//'let' introduced in ES6. Before ES6, we used to use 'var'
//let see the example with var first
for(var i=0;i<10;i++){
console.log('\n' + i);
}
//See how 'i' is accessible outside of for loop, because scope of var keyword is upto nearest function
console.log('\n var keyword value: ' + i); // will
for(let j=0;j<10;j++){
console.log('\n' + j);
}
//'j' is not accessible outside of for loop, because scope of let keyword is upto nearest block
console.log('\n let keyword value: ' + j); // will throw error 'j is not defined'
//Main difference is var & let is about scope. Scope of var keyword is anywhere inside nearest function,
//but scope of let keyword is inside the nearest block only
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.