Rehman Shahid
Difference between var and let
By Rehman Shahid in JavaScript on Jul 22 2017
  • Rehman Shahid
    Jul, 2017 22

    difference between var and let lies in their scope i.e var scope lies to the nearest of function block and let scope lies to the nearest of enclosing blockExample:function demoVarAndLet() {// var variable scopefor (var i = 0; i < 5; i++) {}if (typeof i === 'undefined') {console.log('i(var) is undefiend and not accessible after the loop')} else {console.log('i is accessible after for loop i:' + i + ' type: var ');}for (let j = 0; j < 5; j++) {// let variable scope}if (typeof j === 'undefined') {console.log('j(let) is undefiend and not accessible after the loop');} else {console.log('j is accessible after for loop i:' + i + ' type: let')} }For Live Demo: https://jsfiddle.net/rehmanshahid/3Lnyzd49/

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS