Monday, December 5, 2016

let in js

  1. as Douglas Crockford has said, the worst feature of JavaScript is global variables.
    This has been alleviated greatly by block scoped variables

    consider the following


    var test ="herman"

    {
    test ="boris";
    console.log(test)
    }
    console.log(test)

    or


    var test ="herman"

    {
    var test ="boris";
    console.log(test)
    }
    console.log(test)

    the result will be


    boris
    boris

    However, with the new let keyword

    var test ="herman"

    {
    let test ="boris";
    console.log(test)
    }
    console.log(test)

    the results are now
    boris
    herman

No comments:

Post a Comment