Dab tsi yog hom null hauv JavaScript?
Dab tsi yog hom null hauv JavaScript?

Video: Dab tsi yog hom null hauv JavaScript?

Video: Dab tsi yog hom null hauv JavaScript?
Video: txhob hnov qab kuv lub npe - Bee lee [Official MV] 2022-23 2024, Kaum ib hlis
Anonim

Hauv JavaScript null yog "tsis muaj dab tsi". Nws yuav tsum yog ib yam dab tsi uas tsis muaj nyob. Hmoov tsis zoo, hauv JavaScript , cov ntaub ntawv yam null yog ib yam khoom. Koj tuaj yeem xav tias nws yog kab laum hauv JavaScript tias hom null yog ib yam khoom.

Xav txog qhov no, hom null yog dab tsi?

Cov null tus nqi yog technically ib tug primitive, txoj kev "khoom" los yog "tus naj npawb" yog primitives. Cov null tus nqi, txawm li cas los xij, tau sawv cev ua tus NULL pointer, uas yog 0x00 rau feem ntau platforms. Raws li qhov tshwm sim ntawm qhov zoo sib xws, null muaj 0 hom tag, uas sib raug rau ib yam khoom.

Ib yam li ntawd, koj siv null li cas hauv JavaScript? ' Null' hauv JavaScript ' Null ' yog lo lus tseem ceeb hauv JavaScript uas txhais tau hais tias 'tsis muaj nqi' lossis tsis muaj qhov muaj nqis. Yog tias koj xav rho tawm qhov sib txawv ntawm nws cov nqi, koj tuaj yeem muab ' null ' rau nws. Dhau li ntawm qhov no, zoo li lwm yam khoom, nws yeej tsis raug xa mus rau qhov sib txawv los ntawm JavaScript.

Kuj tseem paub yog, vim li cas hom ntawm null yog qhov khoom hauv JavaScript?

Hauv JavaScript , typeof null yog 'object ', uas incorrectly qhia tias null yog ib khoom (Nws tsis yog, nws yog ib qho tseem ceeb, sab laj kuv blog ncej ntawm categorizing qhov tseem ceeb kom paub meej). Qhov no yog kab laum thiab ib qho uas hmoov tsis tuaj yeem kho tsis tau, vim tias nws yuav ua txhaum cov cai uas twb muaj lawm. Cov ntaub ntawv yog siv rau ib qho khoom.

Puas yog null hom ntaub ntawv?

Muaj NO cov ntaub ntawv hom NULL . NULL nws tus kheej txhais tau tias ABSENCE ntawm cov ntaub ntawv . Thaum tsis muaj cov ntaub ntawv , yuav ua li cas thiaj muaj hom ? Datatype rau NULL yog tsis muaj qab hau li hom ntaub ntawv rau 0: nws tuaj yeem yog INTEGER, FLOAT lossis VARCHAR.

Pom zoo: