> 如果有記憶吐司就好了... # undefined 與 null 的差異 ### undefined 當一個變數沒有被宣告或是已被宣告但沒有被賦予值,則為undefined。 ### null 當一個變數被宣告為null,則代表此變數為空值。 ### 布林 ``` typeof undefined // undefined typeof null // object null === undefined // false null == undefined // true ``` ### 補充說明: **兩者都為"沒有"的意思,但實質上還是有些差異的,當undefined用typeof看為undefined,則null用typeof看為object,表示兩者的型別並不相同。** 參考文獻: * https://codinggirl.timelog.to/a174653905 * https://wcc723.github.io/javascript/2017/12/06/javascript-variables/ * https://pjchender.blogspot.com/2016/03/javascriptby-referenceby-value.html * https://iter01.com/548218.html * https://ithelp.ithome.com.tw/articles/10103799
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up