Puas zoo dua VAR?
Puas zoo dua VAR?

Video: Puas zoo dua VAR?

Video: Puas zoo dua VAR?
Video: Koj Puas Zoo Siab - Chenning Xiong (Official Music Video) 2024, Kaum ib hlis
Anonim

Qhov sib txawv tseem ceeb yog qhov sib txawv, thaum cia tuaj yeem tsuas muaj nyob rau hauv qhov uas nws tau tshaj tawm, xws li nyob rau hauv lub voj, var tuaj yeem nkag mus rau sab nraum lub voj piv txwv. cia tso cai rau koj tshaj tawm cov kev hloov pauv uas txwv tsis pub muaj kev txwv rau qhov thaiv, nqe lus, lossis kev qhia uas nws siv.

Tom qab ntawd, qhov twg zoo dua tso lossis VAR?

cia yog tus tshiab var . Thaj tsuas qhov txawv yog qhov ntawd var tau txais scoped rau cov haujlwm tam sim no, thaum cia tau scoped rau tam sim no block. Thiab yog tias koj xav tau ib yam dab tsi zoo dua hauv kev thaiv lossis ib yam dab tsi, ces koj tuaj yeem ua qhov ntawd thiab. Yog li kuv txoj kev xav yog kom tsis txhob siv var tag nrho thaum sau ES6 code.

Ib tug kuj yuav nug, qhov txawv ntawm VAR thiab cia hauv JS yog dab tsi? var thiab let yog ob qho tib si siv rau kev tshaj tawm sib txawv hauv javascript tab sis cov qhov sib txawv ntawm lawv yog li ntawd var yog function scoped thiab cia yog blocked. Nws tuaj yeem hais tias qhov hloov pauv tau tshaj tawm nrog var yog txhais thoob plaws hauv qhov kev pab cuam raws li piv rau cia.

Raws li qhov tshwm sim, puas cia nrawm dua VAR?

Hais txog kev sib piv kev ua haujlwm, var yog sai dua thiab cia yog qeeb hauv lub voj voog thaum khiav lossis ua tiav cov cai. Rov tshaj tawm var Tshaj tawm qhov sib txawv ntawm tib lub luag haujlwm lossis qhov ua rau nce mus rau Syntax yuam kev whereas cia declared variable tsis tuaj yeem tshaj tawm.

Thaum twg koj yuav tsum siv var tshaj tawm qhov sib txawv ntawm Let?

var tus lej = 5 tus lej = "nyob zoo ntiaj teb" //This yuav tsis compile. Qhov txawv tseem ceeb yog qhov ntawd var sib txawv tus nqi ua tau hloov, thiab cia ua tau 't. Yog koj xav kom muaj tus neeg siv cov ntaub ntawv nkag, koj yuav siv var yog li tus nqi ua tau hloov thiab siv let hom ntaub ntawv sib txawv yog li tus nqi ua tau tsis raug hloov.

Pom zoo: