成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Javascript : var , let and const

cheukyin / 2348人閱讀

Try to share something when I get something to share

ES6 bring in a new scope based on block, before that we only have global and local scope.

The blocked scope declares by let, and below are the goodies:

1.

function hi(){
    let hi = 10;
    let hi = 20; // error out : let cannot be re-declare, var can
    }

2-1.

function hi(){
    let hi = 10;
    if(true){
        let hi = 20;
    }
    console.log(hi);  // log 10;
}

2-2.

function hi(){
    let hi = 10;
    if(true){
        hi = 20;
    }
    console.log(hi); // log 20;
}

3-1.

for(let i = 0; i< 10; i++){
    setTimeout(
    function a() {
        console.log(i); //print 0 to 9
    }, 100 * i);
}

3-2.

for(var i = 0; i< 10; i++){
    setTimeout(
    function a() {
        console.log(i); //print 10 by 10 times
    }, 100 * i);
}

Generally, var is less recommended:

        if( can use const) use const
        else if( can use let) use let
        else use var 

So far, very rare case this could happen, I have to learn more stuff to tell in which specific case, this happens.

Nothing new, just a summary of what I think of all the daily readings.
All above is just for beginners like me. Any meaningful comments are much welcomed and appreciated.

Thanks,

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/107881.html

相關(guān)文章

  • JavaScript機器學(xué)習(xí)之KNN算法

    摘要:是的縮寫,它是一種監(jiān)督學(xué)習(xí)算法。每一個機器學(xué)習(xí)算法都需要數(shù)據(jù),這次我將使用數(shù)據(jù)集。其數(shù)據(jù)集包含了個樣本,都屬于鳶尾屬下的三個亞屬,分別是山鳶尾變色鳶尾和維吉尼亞鳶尾。四個特征被用作樣本的定量分析,它們分別是花萼和花瓣的長度和寬度。 譯者按: 機器學(xué)習(xí)原來很簡單啊,不妨動手試試! 原文: Machine Learning with JavaScript : Part 2 譯者: Fund...

    enrecul101 評論0 收藏0
  • JavaScript 變量聲明提升

    摘要:輸出的結(jié)果為輸出的結(jié)果為提升后輸出的結(jié)果為重新定義了變量輸出的結(jié)果為如果定義了相同的函數(shù)變量聲明,后定義的聲明會覆蓋掉先前的聲明,看如下代碼輸出練習(xí)的值是多少的值是多少第二題的解析請看這里參考資料文章文章中文版鏈接文章推薦文章變量提升 JavaScript 變量聲明提升 原文鏈接 一個小例子 先來看個例子: console.log(a); // undefined var a =...

    fireflow 評論0 收藏0
  • Javascript 關(guān)于array的使用

    摘要:關(guān)于深復(fù)制詳見其他博文方法數(shù)組簡單用法方法的參數(shù)翻譯說傳入一個回調(diào)函數(shù)里面有三個參數(shù)當(dāng)前遍歷的元素當(dāng)前元素的坐標(biāo)以及遍歷的數(shù)組還有一個可選參數(shù),在里面使用就是這個值如果未傳入,則是根據(jù)當(dāng)前執(zhí)行環(huán)境獲取。 Javascript 關(guān)于array的使用 來自: https://luoyangfu.com/detail/... 最近做項目經(jīng)常會使用到數(shù)組,尤其在一個中臺系統(tǒng)中,數(shù)組是尤為常見的...

    zombieda 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<