国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Advanced JS Notebook

jimhs / 976人閱讀

How JavaScript works?
JavaScript is a single-threaded language that can be non-blocking.

JavaScript Engine

For the code below:

const f()=>{
    const ff()=>{
        console.log("a");
        }
    }
f();

f(), ff()and console.log("a") will be push in the call stack one by one and be popped out in the reverse order (first in last out).

Single threaded means the JavaScript Engine has only one call stack. (simple, multithreaded environment is complicated and has many issues like "deadlock" to deal with.)

Synchronous programming means the program gets executed one line after another in order. If we have one function that takes a lot of time, the whole line will be held up.
When we need to do things like image processing or making requests over the network like API calls, we should do asynchronous programming.

JavaScript Run-time environment

We can do asynchronous programming with setTimeout(), for example:

console.log("1");
setTimeout(() => {
    console.log("2");
}, 2000);
console.log("3");
//>> 1, 3, 2

console.log("1") is pushed in the call stack and executed, then popped out;

setTimeout() was pushed in the call stack. Bc it is not part of JavaScript but part of Web APIs, it triggers the Web APIs, then is popped out of the call stack. And the Web APIs starts a timer of 2 seconds.

During the 2 seconds, as the call stack is empty, console.log("3") is pushed in, executed and pushed out.

After 2 seconds, the Web APIs adds a callback of setTimeout to the callback queue, ready to rune the content inside of setTimeout().

The event loop keeps checking the callback stack and only if the call stack is empty, it will push the first thing in the queue to the stack and do some work. So the callback is removed from the callback queue and added in the call stack, and by running it we add console.log("2") in the call stack, when it is done, the callback is popped out. Now everything is empty.

?? if the time in setTimeout() is set to 0, the output order is still the same, bc only if the call stack is empty, it will push the first thing in the queue to the stack and do some work.

?? JavaScript is synchronous in the sense that it is single-threaded but can have asynchronous code by using the event queue on things like AJAX requests.

S Data structures Data types

The latest ECMAScript standard defines seven data types (built-in types):

Six primitive data types:

Boolean

Null

Undefine

Number

String

Symbol (new in ECMAScript6)

Object

Array and Function are two specialized version of the Object type. Use typeof operator to figure out the type of the value that held by a variable (only values have types, variables are only containers):

var a;
typeof a; // >>"undefined"

var b = null;
typeof b; // >>"object"

var c = undefined;
typeof c;// >>"undefined"

typeof function() {} === "function"; // >>"True"

var arr = [1, 2, 3];
typeof arr; // >>"object"
// use Array.isArray or Object.prototype.toString.call
// to differentiate regular objects from arrays

?? typeof null returns Object instead of null is a long-standing bug in JS, but one that is likely never going to be fixed. Too much code on the Web relies on the bug and thus fixing it would cause a lot more bugs!

?? The typeof of arrays is object.

?? A variable value can be undefined by 1. explicitly assignment, 2. declared with no assignment, 3. function return with no value, 4. usage of void operator

Coercion Truthy & Falsy

A non-boolean value can always be coerced to a boolean value. The specific list of "falsy" values are as follows:

empty string: ""

0, -0

invalid number: NaN

null, undefined

false

Equality & Inequality

There are four equality operators: ==, ===, !=, and !==.
Overall, the difference between == and === is that == checks the equality with coercion allowed, and === checks the equality without coercion allowd ("strictly equality").

The Strict Equality Comparison Algorithm (x === y)

check Ecma-262 Edition 5.1 Language Specification here

if: typeof x differs from typeof y, return false

elif: typeof x is "undefine" or "null", return true, else:

elif: typeof x is "number"

if: x or y is NaN, return false (??NaN === nothing)

elif: x is the same number value as y, return true

elif: x is +0, y is -0 and vice versa, return true

else: return false

elif: typeof x is "string"

if: x and y are exactly the same sequence of characters (same length and same characters in corresponding positions), return true

else: return false

elif: typeof x is "boolean"

if: x and y are both "true" or "false", return true

else: return false

elif: typeof x is "object"

if: x and y both refer to the same object, return true

else: retrun false

else: pass

The Abstract Equality Comparison Algorithm (x == y)

if: typeof x is the same as typeof y, return the same result as x === y

elif: typeof x is undefined and typeof y is null, and vice versa, return true

elif: typeof x is "string" and typeof y is "number", return the result of ToNumber(x) == y, and vice versa

elif: typeof x is "boolean", return the result of ToNumber(x) == y, and vice versa ??

elif: typeof x is "object", typeof y is "string" / "number", return the result of ToPremitive(x) == y, and vice versa ??

else: return false

Sameness comparison of == and ===

Relational Comparison

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/98311.html

相關文章

  • JupyterLab:程序員的筆記本神器

    摘要:對于有著完全的支持是一個交互式的開發環境,是的下一代產品,集成了更多的功能,等其正式版發布,相信那時就是被取代的時候通過使用,能夠以靈活,集成和可擴展的方式處理文檔和活動可以開啟終端,用于交互式運行代碼,完全支持豐富的輸出支持,,,等任何文 showImg(https://segmentfault.com/img/remote/1460000018602436?w=1282&h=721...

    rubyshen 評論0 收藏0
  • Jupyter Notebook 安裝插件

    摘要:強烈建議在虛擬環境下使用安裝,這樣就不需要什么或之類的了,也不會搞亂系統級的配置。安裝好后,就可以用命令來執行。親測即使是在虛擬環境中運行的,也會識別同樣的這個文件。 強烈建議在Virtualenv虛擬環境下使用pip安裝,這樣就不需要什么sudo或--user之類的了,也不會搞亂系統級的配置。 一鍵安裝所有東西: # 安裝插件配置器 pip install jupyter_nbext...

    宋華 評論0 收藏0
  • 『 Spark 』5. 這些年,你不能錯過的 spark 學習資源

    摘要:原文鏈接這些年,你不能錯過的學習資源寫在前面本系列是綜合了自己在學習過程中的理解記錄對參考文章中的一些理解個人實踐過程中的一些心得而來。 原文鏈接:『 Spark 』5. 這些年,你不能錯過的 spark 學習資源 寫在前面 本系列是綜合了自己在學習spark過程中的理解記錄 + 對參考文章中的一些理解 + 個人實踐spark過程中的一些心得而來。寫這樣一個系列僅僅是為了梳理個人學習s...

    mist14 評論0 收藏0
  • JS語言核心——“正則表達式的模式匹配”

    摘要:正則表達式一個描述字符模式的對象正則表達式的定義構造函數正則表達式直接量一對斜杠新特性正則的擴展引用類型類型的注意要點用于模式匹配的方法不支持全局搜索忽略表達式參數中的修飾符兩個參數第一個是正則表達式,第二個是要替換的字符串接收一個正則表達 正則表達式(regular expression):一個描述字符模式的對象 1 正則表達式的定義 RegExp()構造函數 正則表達式直接量(一...

    李世贊 評論0 收藏0

發表評論

0條評論

jimhs

|高級講師

TA的文章

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