Variables and Data Types in JavaScript

Kala duwanaanshaha ee JavaScript

Kala duwanaanshaha ama variables waa meel lagu kaydiyo xogta si loo isticmaalo loona maamulo inta barnaamijka lagu jiro. JavaScript waxay leedahay saddex erey oo muhiim ah oo loo isticmaalo in lagu dhawaaqo kala duwanaanshaha: var, let, iyo const.

Variables and Data Types in JavaScript
 Variables and Data Types in JavaScript


  1. var:

    • Ereyga var waxaa loo isticmaalaa in lagu dhawaaqo kala duwanaanshaha ee JavaScript. Kala duwanaanshaha ku dhawaaqay var waxaa lagu soo koobay hawsha, taas oo macnaheedu yahay in ay kaliya laga heli karo hawshaas dhexdeeda.
    • Tusaale:
      javascript

      var da' = 25; console.log(da'); // Wax soo saar: 25
  2. let:

    • Ereyga let waxaa loo isticmaalaa in lagu dhawaaqo kala duwanaanshaha ee lagu soo koobay block-ga, taas oo macnaheedu yahay in ay kaliya laga heli karo block-kaas dhexdiisa. Tani waxay ka dhigaysaa let mid ku habboon in loo isticmaalo loops iyo xaaladaha shuruudaha.
    • Tusaale:
      javascript

      let magac = "John"; if (true) { let magac = "Doe"; console.log(magac); // Wax soo saar: Doe } console.log(magac); // Wax soo saar: John
  3. const:

    • Ereyga const waxaa loo isticmaalaa in lagu dhawaaqo kala duwanaanshaha aan dib loo cusboonaysiin karin ka dib markii la isticmaalay. Kala duwanaanshaha const sidoo kale waa block-ku-soo-koobay sida let. Waxaa badanaa loo isticmaalaa qiimaha aan is beddelin inta barnaamijka la fulinayo.
    • Tusaale:
      javascript

      const pi = 3.14; console.log(pi); // Wax soo saar: 3.14

Noocyada Xogta ee JavaScript

JavaScript waxay taageertaa noocyo kala duwan oo xogta ah si loo kaydiyo noocyo kala duwan oo qiime ah. Noocyada xogta ugu muhiimsan waa:

  1. String:

    • Waxaa loo isticmaalaa in lagu matalo xogta qoraalka. Strings waxaa lagu dhex xiraa hal-fallaadh ('), labanlaab-fallaadh ("), ama backticks (`).
    • Tusaale:
      javascript

      let salaanta = "Hello, World!"; console.log(salaanta); // Wax soo saar: Hello, World!
  2. Number:

    • Waxaa loo isticmaalaa in lagu matalo nambarada integer-ka iyo kuwa floating-point.
    • Tusaale:
      javascript

      let da' = 30; let qiimo = 19.99; console.log(da'); // Wax soo saar: 30 console.log(qiimo); // Wax soo saar: 19.99
  3. Boolean:

    • Waxay matalaysaa sheyga loojiga waxayna yeelan kartaa laba qiime: true ama false.
    • Tusaale:
      javascript

      let waaLaGaliYey = true; let waaMaamul = false; console.log(waaLaGaliYey); // Wax soo saar: true console.log(waaMaamul); // Wax soo saar: false
  4. Array:

    • Waa ururin shey oo ku kaydsan hal variable. Arrays waa kuwa la nidaamiyay waxaana la tixraacaa laga bilaabo eber.
    • Tusaale:
      javascript

      let midabada = ["casaan", "cagaar", "buluug"]; console.log(midabada[0]); // Wax soo saar: casaan
  5. Object:

    • Waa ururin lamaane-key. Objects waxaa loo isticmaalaa in lagu kaydiyo qaab-dhismeed xogta oo adag.
    • Tusaale:
      javascript

      let qof = { magacKowaad: "John", magacDambe: "Doe", da': 25 }; console.log(qof.magacKowaad); // Wax soo saar: John
  6. Undefined iyo Null:

    • undefined waxay tilmaamaysaa in variable la dhawaaqay laakiin aan la siinin qiime.
    • null waxay matalaysaa maqnaanshaha ulajeedada ah ee qiimaha sheyga.
    • Tusaale:
      javascript

      let aanLadhexGalinin; let maqan = null; console.log(aanLadhexGalinin); // Wax soo saar: undefined console.log(maqan); // Wax soo saar: null

Adigoo si wanaagsan u fahmaya kuna isticmaalaya kala duwanaanshaha iyo noocyada xogta si haboon, waxaad abuuri kartaa barnaamijyo JavaScript ah oo firfircoon oo dabacsan.

Previous Post Next Post