Skip to main content

Ma Variables

Not yet Revised

Variable Chii?#

Kuti unzwisise kuti ma variables chii, ndichapa muenzaniso we hembe yaunofarira . Ngatimboti iwewe une hembe yaunofarira, hembe iyoyo ndeye red. Iwewe ukuda kutuma mumwe munhu asingazive nezvehembe dzako kunotora hembe yaunofarira kwayakarongedzwa. Ukangoudza munhu uyu, kuti “enda kunotora hembe yandofarira”, munhu uyu achakubvunza kuti hembe yaunofarira yakaita sei, nekuti akaenda kunoitsvaga iye asingaizive haamboiwane.

Tsananguro
  • Uchishandisa muenzaniso uyu, munhu wauri kutuma i computer.

  • Iwewe ndiwe munhu ari kuda kunyora code ne Shonascript kunotsvaga hembe yaunofarira.

  • Variable apa i hembe yaunofarira, hembe yaunofarira yacho “ndeye red”

Manyorerwo ema variables#

Saka unotaura sei necomputer nezve hembe yaunofarira? Unofana kunyora code inotaura ne computer seizvi:

Chii chikuitika apa?🤯

Ngatimbotarisa ku left kwe equal sign (=).

Tanyora ma words 2 epa hembe yandinofarira akabatana kuita hembeYandinofarira. Manyorero aya anonzi lower camel casing. Unogona kuverenga nezvayo pano. Kana tichinyora ma variables, ku left kwemabrackets kunoiswa word one rakabatanidzwa. Izvi ndizvo zvinonzwisiswa ne computer. Unogona kubatanidza ma words aye kuita hembe_yandinofarira kana kuti HembeYandinofarira kana kuti hembeyandinofarira.

Ukaisa ma words 2 kuti hembe yandinofarira = "ndeye red", computer ichafunga kuti ukuedza kunyora two ma variables hembe na yandinofarira panguva imwe chete, saka inokuudza kuti manyorero awaita hembe yandinofarira haasiriwo. Tarisa mamwe manyorero asinganzwisiswe ne computer mu box re red pazasi

Manyorero ekuleft side asingaite

hembe yandinofarira = "ndeye red" -> ku left kunofana kuenda one word

1hembeYandinofarira = "ndeye red" -> usatange zita revariable ne number kana !@#$%^&*

hembe-yandinofarira = "ndeye red" -> usaise hyphen(-) muzita re variable, asi unogona kushandisa underscore () kubatanidza ma _words kuita one sezvambotaurwa

Manyorero ekuleft side anoita

hembeYandinofarira = "ndeye red"

HembeYandinofarira = "ndeye red"

hembe_yandinofarira = "ndeye red"

Ngatichitarisa ku right kwe equal sign (=)

Chekutanga, unoona kuti pane ma quotes (""). Zvinhu zvese zviri mu ma quotes zvinoverengwa ne computer se chinhu chimwe chete, semashoko, uye zvinoverengwa sezvazviri. Ukasaisa ma quotes ukati hembeYandinofarira = ndeye red, computer ichatarisa kuti chinhu chiri kuright kwe equal sign (=) ichiedza kuda kuona kuti:

  1. i nhamba here? - haisi
  2. imwe code ine zvainoreva zvinozivikanwa ne Shonascript here? - haisi

    code ine zvainoreva iri kutaurwa apa uchazoiziva kumberi ukaramba uchiverenga

Saka kana computer yaona kuti ku right hakuna zvinhu izvi, ichaona sokuti zvese zviri kuright i variable. Asi ku right kune 2 mashoko aisira muma quotes, saka ichaona kunge urikuda kunyora 2 ma variables panguva imwe chete yokuudza kuti manyorero awaita haasiriwo. Asi kana kuright kwacho kuine word rimwe chete, sokuti hembeYandinofarira = red, computer ichaona kuti waisa variable ku right, yoedza kutsvaga kuti variable inonzi red yambogadzirwa here mu code yako.

Kugadzira variable kuita sei?

Kugadzira variable ndiko kuti zitaReVariable = "zvimwe zvinhu" zvakafanana nekuti hambeYandinofarira = "ndeye red". Apa panenge pachigadzirwa variable inonzi hembeYandinofarira

Kana computer ikashaya variable inonzi red yairi kutsvaga, inonyora kuti variable inonzi red haisi kuzivikanwa.

Unoona sei kuti variable yako yadzirwa?#

kunyora uchishandisa nyora()

Pane anonzi ma functions, auchazoziva pauchaverenga nezve topic yema functions. Munhu anoshandisa ma functions kana achida kutuma computer kuti iite basa. Shonascript ine function inoita basa rekunyora zvaukuda kuona inonzi nyora(). Enda kumberi kana uchida kuona kuti nyora() anoshanda sei. Izvi zvichakubatsira kunzwisisa mashandiro ema variables.