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
摘要:是的縮寫,它是一種監(jiān)督學(xué)習(xí)算法。每一個機器學(xué)習(xí)算法都需要數(shù)據(jù),這次我將使用數(shù)據(jù)集。其數(shù)據(jù)集包含了個樣本,都屬于鳶尾屬下的三個亞屬,分別是山鳶尾變色鳶尾和維吉尼亞鳶尾。四個特征被用作樣本的定量分析,它們分別是花萼和花瓣的長度和寬度。 譯者按: 機器學(xué)習(xí)原來很簡單啊,不妨動手試試! 原文: Machine Learning with JavaScript : Part 2 譯者: Fund...
摘要:輸出的結(jié)果為輸出的結(jié)果為提升后輸出的結(jié)果為重新定義了變量輸出的結(jié)果為如果定義了相同的函數(shù)變量聲明,后定義的聲明會覆蓋掉先前的聲明,看如下代碼輸出練習(xí)的值是多少的值是多少第二題的解析請看這里參考資料文章文章中文版鏈接文章推薦文章變量提升 JavaScript 變量聲明提升 原文鏈接 一個小例子 先來看個例子: console.log(a); // undefined var a =...
摘要:關(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ù)組是尤為常見的...
閱讀 886·2023-04-25 21:21
閱讀 3254·2021-11-24 09:39
閱讀 3102·2021-09-02 15:41
閱讀 2039·2021-08-26 14:13
閱讀 1856·2019-08-30 11:18
閱讀 2822·2019-08-29 16:25
閱讀 535·2019-08-28 18:27
閱讀 1614·2019-08-28 18:17