JavaScript 型別

傅勝華
Jul 16, 2021

--

JS是動態型別 (dynamic Typing) ,意思是不用特地給變數型別,會根據它的值給予型別,甚至會做強制轉型 (coercion)

型別分原始型別 (primitive type 、 純值)物件 (object) ,純值又分六種

純值 (primitive type)

undefined--為變數預設值,意思為"尚未設置"

null--意思也為"尚未設置",但非預設值,可與 undefined 作區別

bollean--布林值, TRUE 和 FALSE (字串的 "TRUE" 不等於 TURE,FALSE類推)

number--JS 的 number 為浮點數 (floating number)

string--字串

symbol--為ES6的新型別

強制轉型 (coercion)

分為 明確的強制轉型(explicit coercion) 隱含的強制轉型(implicit coercion)

明確的強制轉型,是作者有明文寫出讓其轉型,如: parseInt()。

隱含的強制轉型,是 JS 的解析器 (syntax parser)轉換
,如:2 == "2" => ture

Ref
JavaScript 全攻略:克服 JS 的奇怪部分
你懂 JavaScript 嗎?#8 強制轉型(Coercion)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

傅勝華
傅勝華