JS基础教程——JavaScript基础知识(2.1.1变量的类型)

2014-4-16 liyangweb.com 李杨 JavaScript

    正像介绍JavaScript常量那样,JavaScript与Java等编辑语言并不相同,我们熟知,Java中有固定的数据类型,如int型、float型,虽然JavaScript中有这些数据类型,但是在声明中无需对变量进行声明。这就意味着JavaScript的变量可以存放任何类型的值。例如,下例中将一个变量复制给整数,然后将一个boolean值直接赋值给它,这是完全合法的:

x=100;
x=true;

虽然这些在JavaScript中合法,但是熟知C、C++、Java的人会发现,这样的赋值咋编程中是绝对不能出现的。不过正是由于JavaScript的这种缺少类型的规则,是的JavaScript在必要时刻可以快速、自动的完成两种不同类型的转换。例如,在前面的例子中已经可以看到,如果一个数值和字符串连接,只需要将两个不同的变量或者常量用“+”相连即可。

    由于没有类型规则,所以JavaScript只能算是一种简单的语言,用于完成以下短小精悍的脚本任务,所以它并不是很精准;但是Java和C++在编程时却要使用严格的程序设计规则,一遍使编写、维护和重用这些较长的程序更容易。

    JavaScript变量的类型可以分为全局变量和局部变量。全局变量,也成为外部变量,它是在函数外部定义的变量。它不属于哪一个函数,而属于一个源程序文件,其作用域整个源程序。在函数中使用全局变量,一般应作全局变量说明。在程序的顶层代码中,可以使用JavaScript的关键字this来引用全局变量。在函数内部,this则有其他用途,具体用途会在以后介绍。

    局部变量是特殊的全局兑现的属性。它们是一个对象的属性,这个对象被称为调用对象。

标签: JavaScript JS基础教程

评论:

rebeccastaste
2019-02-09 15:19
<a href="http://www.agichipay.com/detroit-lions-jason-hanson-jersey-nflv">detroit lions jason hanson jersey</a> <a href="http://www.millsbulb.com/adidas-neo-hemp-rope-casual-shoes-mens-skof">adidas neo hemp rope casual shoes mens</a> <a href="http://www.hamshrd.com/nike-free-grey-pink-rubber-shoe-woman-skob">nike free grey pink rubber shoe woman</a> <a href="http://www.lroyroofing.com/texas-rangers-snapback-mitchell-and-ness-hate">texas rangers snapback mitchell and ness</a> <a href="http://www.golfbodyshop.com/nike-shox-tlx-menns-runningf">nike shox tlx menns</a> <a href="http://www.yufnsyb.com/herre-nike-roshe-yeezy-boost-bl%C3%A5-lyser%C3%B8d-schuhea">herre nike roshe yeezy boost bl氓 lyser酶d</a>
rebeccastaste http://www.rebeccastaste.com/
shonema
2019-02-05 02:44
<a href="http://www.lagunawoodsre.com/nike-zoom-structure-18-hvit-s%C3%B8lv-obuvj">nike zoom structure 18 hvit s酶lv</a> <a href="http://www.highbacklink.com/maschio-nike-roshe-run-speckle-gituttio-viola-scarpep">maschio nike roshe run speckle gituttio viola</a> <a href="http://www.vuurogen.com/hommes-nike-roshe-run-violet-oranger-chaussuresh">hommes nike roshe run violet oranger</a> <a href="http://www.rsvppersonnel.com/prada-vela-messenger-bag-pradah">prada vela messenger bag</a> <a href="http://www.shonema.com/lebron-james-blue-and-orange-cavs-jersey-nfli">lebron james blue and orange cavs jersey</a> <a href="http://www.enventsurvey.com/kvinders-nike-roshe-run-triangle-lyser%C3%B8d-appelsin-skoq">kvinders nike roshe run triangle lyser酶d appelsin</a>
shonema http://www.shonema.com/
michigangolfguide
2019-01-29 11:49
<a href="http://www.artenvironments.net/flyknit-trainer-rosa-blau-earth-obuvd">flyknit trainer rosa blau earth</a> <a href="http://www.ascential.net/nike-air-max-95-tout-bleu-obuvg">nike air max 95 tout bleu</a> <a href="http://www.associazioneagape.net/nike-kaishi-korall-color-schuhef">nike kaishi korall color</a> <a href="http://www.atientertainment.net/dam%C3%A4nner-nike-air-max-95-wei%C3%9F-rosa-obuve">dam盲nner nike air max 95 wei脽 rosa</a> <a href="http://www.attawhed.net/kvinders-nike-roshe-run-blomstret-khaki-butye">kvinders nike roshe run blomstret khaki</a> <a href="http://www.audichandler.net/air-max-90-infrarot-herren-zen-obuvd">air max 90 infrarot herren zen</a>
michigangolfguide http://www.michigangolfguide.net/
kolsyreis
2019-01-02 05:06
<a href="http://www.mrforgps.com/nike-tanjun-bl%C3%A5-lyser%C3%B8d-butyf">nike tanjun bl氓 lyser酶d</a> <a href="http://www.psychedelicsf.com/nike-roshe-run-high-rosso-bianca-butyf">nike roshe run high rosso bianca</a> <a href="http://www.seminarioeam.com/adidas-zx-700-bleu-ciel-argent-obuvf">adidas zx 700 bleu ciel argent</a> <a href="http://www.tedsrcrepair.com/hombres-nike-roshe-yeezy-boost-verde-negro-obuve">hombres nike roshe yeezy boost verde negro</a> <a href="http://www.arenewedimage.com/air-jordan-eclipse-venta-kurpesg">air jordan eclipse venta</a> <a href="http://www.daftarkursus.com/adidas-crazy-light-4-boost-for-verkauf-obuvc">adidas crazy light 4 boost for verkauf</a>
kolsyreis http://www.kolsyreis.com/
ictbel
2019-01-01 20:16
<a href="http://www.hotelfuat.com/yellow-green-womens-nike-mercurial-vapor-shoes-skob">yellow green womens nike mercurial vapor shoes</a> <a href="http://www.pmisaltriver.com/new-york-yankees-hat-sticker-labels-hatc">new york yankees hat sticker labels</a> <a href="http://www.ductambag.com/roshe-run-maroon-nike-runninge">roshe run maroon nike</a> <a href="http://www.priverussia.com/nike-roshe-run-high-blanc-blanc-ventes-schuhea">nike roshe run high blanc blanc ventes</a> <a href="http://www.coatsfrance.com/jordan-13-gr%C3%A5-orange-scarpec">jordan 13 gr氓 orange</a> <a href="http://www.intoloo.com/nike-air-max-2019-green-uk-shoeso">nike air max 2019 green uk</a>
ictbel http://www.ictbel.com/
kodakid
2018-12-30 06:59
<a href="http://www.starizle.com/nike-mercurial-vapor-jaune-noir-kurpesb">nike mercurial vapor jaune noir</a> <a href="http://www.notpotatoes.com/hvit-jordan-12-ovo-kurpesd">hvit jordan 12 ovo</a> <a href="http://www.tedxuon.com/air-jordan-retro-14-ni%C3%B1os-naranja-verde-kurpesc">air jordan retro 14 ni帽os naranja verde</a> <a href="http://www.thejuicylucy.com/nike-air-max-97-femminile-blu-rosa-scarpec">nike air max 97 femminile blu rosa</a> <a href="http://www.almanyaonline.com/nike-air-huarache-iii-gr%C3%A5-rosa-schuhee">nike air huarache iii gr氓 rosa</a> <a href="http://www.trademelikes.com/air-jordan-retro-5-rosado-obuvf">air jordan retro 5 rosado</a>
kodakid http://www.kodakid.com/
reddotsmedia
2018-12-29 01:11
<a href="http://www.cakeeaterspgh.com/air-jordan-1-brosso-high-strap-kurpesc">air jordan 1 brosso high strap</a> <a href="http://www.itlooksohot.com/lebron-12-svart-crimson-r%C3%B8d-obuvf">lebron 12 svart crimson r酶d</a> <a href="http://www.naijareward.com/kvinners-nike-air-max-2015-all-gr%C3%B8nn-scarped">kvinners nike air max 2015 all gr酶nn</a> <a href="http://www.nhadatmoivn.com/roshe-run-schwarz-wei%C3%9F-hyper-punch-butya">roshe run schwarz wei脽 hyper punch</a> <a href="http://www.piernowedding.com/adidas-projoator-instinct-fg-negro-solar-rojo-chaussurese">adidas projoator instinct fg negro solar rojo</a> <a href="http://www.storagelayout.com/air-huarache-run-ultra-nero-mono-butya">air huarache run ultra nero mono</a>
[url=http://www.reddotsmedia.com/]reddotsmedia[/url]
soflexdance
2018-12-27 11:41
<a href="http://www.atastymorsel.com/nike-dam%C3%A4nner-roshe-run-knit-trainer-kurpesa">nike dam盲nner roshe run knit trainer</a> <a href="http://www.beaudoutjoel.com/new-balance-577-maschiota-verde-butyg">new balance 577 maschiota verde</a> <a href="http://www.blockchainmkt.com/nike-kevin-huber-mens-black-limited-jersey-10-nfl-cincinnati-bengals-player-name-number-tank-top-nflw">nike kevin huber mens black limited jersey 10 nfl cincinnati bengals player name number tank top</a> <a href="http://www.ceeditsesame.com/new-balance-m1500gl-classic-light-gr%C3%A5-hvid-butye">new balance m1500gl classic light gr氓 hvid</a> <a href="http://www.fotodardo.com/nike-air-max-95-leder-rosa-blau-kurpesc">nike air max 95 leder rosa blau</a> <a href="http://www.meghanfresta.com/vert-noir-polo-shirt-polow">vert noir polo shirt</a>
soflexdance http://www.soflexdance.com/

发表评论:

Powered by emlog 冀ICP备13011830号-1