Puas yog cov chav kawm hoisted hauv JavaScript?
Puas yog cov chav kawm hoisted hauv JavaScript?

Video: Puas yog cov chav kawm hoisted hauv JavaScript?

Video: Puas yog cov chav kawm hoisted hauv JavaScript?
Video: Leng Yang - Yog Vim Dab Tsi (Official Full Song | Nkauj Tawm Tshiab) 2020/05/24 2024, Kaum ib hlis
Anonim

Ntau yam zoo li lawv cov haujlwm ua haujlwm, chav kawm JavaScript tshaj tawm yog nqa . Txawm li cas los xij, lawv nyob twj ywm uninitialized kom txog thaum kev ntsuam xyuas. Qhov no txhais tau hais tias koj yuav tsum tshaj tawm a chav kawm ua ntej koj yuav siv tau.

Tsis tas li ntawd, chav kawm JavaScript yog dab tsi?

Cov chav kawm hauv JavaScript yog ib tug tshwj xeeb syntax rau nws prototypical qub txeeg qub teg qauv uas yog ib tug piv txwv nyob rau hauv chav kawm -raws li hom lus taw qhia. Cov chav kawm tsuas yog cov haujlwm tshwj xeeb ntxiv rau ES6 uas yog txhais tau tias yuav ua raws li chav kawm lo lus tseem ceeb los ntawm lwm yam lus no.

Ib yam li ntawd, hoisting hauv JavaScript nrog piv txwv yog dab tsi? Hoisting yog cov JavaScript tus neeg txhais lus qhov kev txiav txim ntawm kev txav txhua qhov sib txawv thiab cov lus tshaj tawm ua haujlwm mus rau sab saum toj ntawm qhov tam sim no. (function() { var foo; var bar; var baz; foo = 1; alert(foo + "" + bar + " " + baz); bar = 2; baz = 3; })(); Tam sim no nws ua rau kev nkag siab vim li cas qhov thib ob piv txwv tsis tau tsim ib qho kev zam.

Ntawm no, cov lus hais hauv chav kawm hoisted?

Hoisting Class Expressions Ib yam li muaj nuj nqi cov lus qhia , cov lus qhia hauv chav kawm kuj tsis yog nqa.

Puas yog cia thiab Const hoisted?

Yog li, los teb koj cov lus nug, yog, cia thiab const hoist tab sis koj tsis tuaj yeem nkag mus rau lawv ua ntej qhov kev tshaj tawm tiag tiag raug ntsuas ntawm lub sijhawm ua haujlwm. ES6 qhia Cia variables uas tuaj nrog block theem scope. Thaum koj txhais qhov sib txawv nrog var lo lus tseem ceeb, nws paub tag nrho cov haujlwm txij li lub sijhawm nws tau txhais.

Pom zoo: