好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

javascript中逻辑运算符和逗号运算符的流程控制功能

逻辑运算符&&的短路特性:

&&运算过程:

首先计算左边表达式的值:
  若值为假或相当于假的值,则直接返回左边表达式的值,不继续计算右边表达式;
  若值为真或相当于真的值,则继续计算右边表达式的值,然后返回右边表达式的值。

例子:

// 左边为假的情况,直接返回左边表达式的值
var a = false && 10;
alert(a);			// false
a = 1<0 && 10;
alert(a);			// false
a = null && 10;
alert(a);			// null
a = undefined && 10;
alert(a);			// undefined
a = NaN && 10;
alert(a);                       // NaN
a = 0 && 10;
alert(a);			// 0
a = '' && 10;
alert(a);			// ''
a = 0.0 && 10;			// 0.0....后面可接多个0
alert(a);			// 0

// 左边为真的情况,继续右边表达式的计算,返回右边表达式的值10
a = true && 10;
alert(a);
a = 1>0 && 10;
alert(a);
a = '0' && 10;
alert(a);
a = {} && 10;
alert(a);
a = [] && 10;
alert(a);
a = function() {} && 10;
alert(a);
a = function() { return 0; } && 10;
alert(a);

与&&运算符流程控制表达式

可以直接丢弃表达式的值,直接采用&&的短路特性进行流程控制,一个小例子:

function a() {
	return false;
}
function b() {
    return true;
}
function c() {
    alert(d);
}
var d = '第一个表达式c函数不被调用,没有输出';
a() && c();
d = '第二个表达式c函数被调用,输出';
b() && c();

逻辑运算符或||的短路特性:

||运算过程:

首先计算左边表达式的值:
  若值为真或相当于真的值,则直接返回左边表达式的值,不继续计算右边表达式;
  若值为假或相当于假的值,则继续计算右边表达式的值,然后返回右边表达式的值。

例子:

// 左边为真的情况,返回左边表达式的值
var a = true || 10;
alert(a);                            // true
a = 1>0 || 10;
alert(a);                            // true
a = '0' || 10;
alert(a);                            // '0'
a = {} || 10;
alert(a);                            // [object Object]
a = [] || 10;
alert(a);                            // ''
a = function() {} || 10;
alert(a);                            // function () {}
a = function() { return 0; } || 10;
alert(a);                            // function () {return 0;}

// 左边为假的情况,继续右边表达式的计算,返回右边表达式的值10
a = false || 10;
alert(a);
a = 1<0 || 10;
alert(a);
a = null || 10;
alert(a);
a = undefined || 10;
alert(a);
a = NaN || 10;
alert(a);
a = 0 || 10;
alert(a);
a = '' || 10;
alert(a);
a = 0.0 || 10;	    // 0.0....后面可接多个0
alert(a);

或||运算符流程控制表达式

小例子:

function a() {
	return false;
}
function b() {
    return true;
}
function c() {
    alert(d);
}
var d = '第一个表达式c函数被调用,输出';
a() || c();
d = '第二个表达式c函数不被调用,没有输出';
b() || c();

逗号运算符

逗号运算符运算过程:

逗号运算符表示从左到右计算表达式的值,返回最后一个表达式的值。
需要注意:逗号运算符的优先级是最低的。

例子:

var a;
// 逗号,运算符优先级低于赋值运算符=,因此a为1
a=1,2,3;
alert(a);
// 利用括号改变优先级,此时a为3
a=(1,2,3);
alert(a);

逗号运算符流程控制表达式:

分号确定表达式结束,区别例子:var连续声明

// 逗号运算符实现连续声明
alert(a);alert(b);alert(c);    // 均输出undefined,表示都声明成功
var a=1,b=2,c=3;
alert(''+a+b+c);               // 输出'123'

// 分号造成错误
alert(a);    // a声明成功,输出undefined
alert(b);    // b声明失败,报错,停止向下运行
alert(c);
var a=1;b=2;c=3;
alert(''+a+b+c);

利用逗号表达式获取函数返回值:

function a() {
    var b = 1;
    var c = 2;
    return b++,c++,b+c;
}
// 首先b++,则b=2,然后c++,则c=3,最后b+c=5,则完整逗号表达式的值为5,函数返回5
alert(a());    // 输出5


小指才疏学浅,有任何疏漏之处,请不吝赐教~

点赞0
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
jennyreinio
 jennyreinio 2019-05-21 21:23回复
#208
<a href="http://www.bluesophy.com/nike-free-tr-flyknit-5.0-marrone-oro-kurpesd">nike free tr flyknit 5.0 marrone oro</a> <a href="http://www.stylehousestl.com/nike-mercurial-superfly-v-fg-footballe-gold-wei%C3%9F-schuhel">nike mercurial superfly v fg footballe gold wei脽</a> <a href="http://www.byvergara.com/nike-air-max-1-dark-army-gr%C3%B8nn-skof">nike air max 1 dark army gr酶nn</a> <a href="http://www.ruthlesscrew.com/asics-gel-noosa-tri-7-gr%C3%B8n-brun-footf">asics gel noosa tri 7 gr酶n brun</a> <a href="http://www.fullserviceap.com/salomon-speedcross-3-union-blu-version-sneakerd">salomon speedcross 3 union blu version</a> <a href="http://www.idealkizlar.com/nike-air-max-plus-volt-svart-neon-gr%C3%B8nn-schuhef">nike air max plus volt svart neon gr酶nn</a>
jennyreinio http://www.jennyreinio.com/
texarillo
 texarillo 2019-05-21 10:08回复
#207
<a href="http://www.theislandbody.com/nike-zoom-winflo-2-himmelen-bl%C3%A5-gull-obuvi">nike zoom winflo 2 himmelen bl氓 gull</a> <a href="http://www.zululeads.com/mujeres-nike-lunarglide-7-amarillo-rojo-zapatosp">mujeres nike lunarglide 7 amarillo rojo</a> <a href="http://www.notmyrichie.com/adidas-springblade-solyce-hvid-sort-skol">adidas springblade solyce hvid sort</a> <a href="http://www.mintyschoice.com/maschio-nike-free-run-3-gituttio-nero-scarpeh">maschio nike free run 3 gituttio nero</a> <a href="http://www.mamapjblog.com/femminile-air-jordan-retro-12-verde-grigio-scarpei">femminile air jordan retro 12 verde grigio</a> <a href="http://www.pdfunicorn.com/schwarz-nike-shox-preschool-schuheh">schwarz nike shox preschool</a>
texarillo http://www.texarillo.com/
hozloli
 hozloli 2019-05-20 20:46回复
#206
<a href="http://www.michiganev.com/nike-air-force-1-wei%C3%9F-gum-schuheh">nike air force 1 wei脽 gum</a> <a href="http://www.serdarhan.com/converse-chuck-taylor-navy-blue-shoesk">converse chuck taylor navy blue</a> <a href="http://www.ankaralimnet.com/kvinder-adidas-superstar-lilla-rose-skoj">kvinder adidas superstar lilla rose</a> <a href="http://www.greenwichua.com/adidas-11pro-schwarz-schuheh">adidas 11pro schwarz</a> <a href="http://www.minicomposer.com/blue-adidas-climacool-shoesk">blue adidas climacool</a> <a href="http://www.tabletopsport.com/michael-kors-navy-womens-satchel-bag-mkh">michael kors navy womens satchel bag</a>
hozloli http://www.hozloli.com/
deshiresult
 deshiresult 2019-05-20 16:21回复
#205
<a href="http://www.hopitalhayek.com/jordan-11-blanco-oro-pinnacle-zapatosk">jordan 11 blanco oro pinnacle</a> <a href="http://www.cheapartsale.com/womens-adidas-nmd-runner-yellow-shoesj">womens adidas nmd runner yellow</a> <a href="http://www.xjdscnuh.com/colorado-rockies-47-mlb-on-field-replica-47-mvp-cap-hath">colorado rockies 47 mlb on field replica 47 mvp cap</a> <a href="http://www.cybcarusa.com/nike-free-trainer-5.0-negro-and-azul-zapatosl">nike free trainer 5.0 negro and azul</a> <a href="http://www.drfoxxdds.com/nike-kobe-7-black-gold-shoesk">nike kobe 7 black gold</a> <a href="http://www.hagemannlaw.com/nike-air-max-gr%C3%A5-gr%C3%B8nn-obuvi">nike air max gr氓 gr酶nn</a>
deshiresult http://www.deshiresult.com/
lsu knit hat
 lsu knit hat 2019-05-20 12:15回复
#204
<a href="http://www.cd-niordc.com/widely/%d1%81%d0%b0%d0%bc%d0%b0%d1%8f-%d0%bc%d0%be%d0%b4%d0%bd%d0%b0%d1%8f-%d0%be%d0%b1%d1%83%d0%b2%d1%8c-%d1%81%d0%b5%d0%b7%d0%be%d0%bd%d0%b0-%d0%b2%d0%b5%d1%81%d0%bd%d0%b0-%d0%bb%d0%b5%d1%82%d0%be-2017-%d1%84%d0%be%d1%80%d0%bc%d0%b0-%d0%b8-%d1%82%d0%b8%d0%bf%d1%8b-marie-c-aire">褋邪屑邪褟 屑芯写薪邪褟 芯斜褍胁褜 褋械蟹芯薪邪 胁械褋薪邪 谢械褌芯 2017 褎芯褉屑邪 懈 褌懈锌褘 marie c aire</a><a href="http://www.cd-niordc.com/yeezy/%d0%b6%d0%b5%d0%bd%d1%81%d0%ba%d0%b8%d0%b5-%d0%b4%d0%b5%d0%bc%d0%b8%d1%81%d0%b5%d0%b7%d0%be%d0%bd%d0%bd%d1%8b%d0%b5-%d0%b7%d0%b0%d0%bc%d1%88%d0%b5%d0%b2%d1%8b%d0%b5-%d1%81%d0%b0%d0%bf%d0%be%d0%b3%d0%b8-christian-dior">卸械薪褋泻懈械 写械屑懈褋械蟹芯薪薪褘械 蟹邪屑褕械胁褘械 褋邪锌芯谐懈 christian dior</a><a href="http://www.cd-niordc.com/york/%d0%be%d0%b4%d0%b5%d0%b6%d0%b4%d0%b0-%d1%81%d1%82%d0%be%d0%ba-%d1%81%d0%b5%d0%ba%d0%be%d0%bd%d0%b4-%d1%85%d0%b5%d0%bd%d0%b4-%d0%be%d0%bf%d1%82%d0%be%d0%bc-%d0%b8%d0%b7-%d0%b5%d0%b2%d1%80%d0%be%d0%bf%d1%8b-%d0%b0%d0%bd%d0%b3%d0%bb%d0%b8%d1%8f-%d0%b1%d0%b5%d0%b7-%d0%bf%d0%be%d1%81%d1%80%d0%b5%d0%b4%d0%bd%d0%b8%d0%ba%d0%be%d0%b2">芯写械卸写邪 褋褌芯泻 褋械泻芯薪写 褏械薪写 芯锌褌芯屑 懈蟹 械胁褉芯锌褘 邪薪谐谢懈褟 斜械蟹 锌芯褋褉械写薪懈泻芯胁</a><a href="http://www.costa-rica-news.com/also/%d1%84%d0%be%d1%82%d0%be-%d1%82%d0%b5%d0%bf%d0%bb%d1%8b%d0%b9-%d0%ba%d0%be%d1%81%d1%82%d1%8e%d0%bc-evo-%d0%b4%d0%bb%d1%8f-%d0%b1%d0%b5%d1%80%d0%b5%d0%bc%d0%b5%d0%bd%d0%bd%d1%8b%d1%85-kostyum-tep-y-evo-4-kostyum-tep-y-evo-5">褎芯褌芯 褌械锌谢褘泄 泻芯褋褌褞屑 evo 写谢褟 斜械褉械屑械薪薪褘褏 kostyum tep y evo 4 kostyum tep y evo 5</a>
lsu knit hat http://www.gubukbelajar.com/sportswear/lsu-knit-hat
timxes
 timxes 2019-05-20 12:11回复
#203
<a href="http://www.avantajreyonu.com/nike-air-max-1-r%C3%B8d-svart-obuvi">nike air max 1 r酶d svart</a> <a href="http://www.oranjeskishop.com/asics-gel-kinsei-5-flash-arancia-scarpek">asics gel kinsei 5 flash arancia</a> <a href="http://www.johannafrost.com/adidas-stan-smith-suede-pink-shoesi">adidas stan smith suede pink</a> <a href="http://www.rolandviet.com/nike-cortez-negro-suede-zapatosi">nike cortez negro suede</a> <a href="http://www.classmedya.com/air-jordan-3-r%C3%B8d-cem%C3%A6ndt-skoh">air jordan 3 r酶d cem忙ndt</a> <a href="http://www.anteageserums.com/converse-tutti-star-nero-bianca-scarpei">converse tutti star nero bianca</a>
timxes http://www.timxes.com/
ikmsdkravmaga
 ikmsdkravmaga 2019-05-20 05:20回复
#202
<a href="http://www.mwartsdrama.com/air-jordan-retro-1-kvinners-oransje-r%C3%B8d-obuvk">air jordan retro 1 kvinners oransje r酶d</a> <a href="http://www.meshmotors.com/coach-chelsea-handbag-coachh">coach chelsea handbag</a> <a href="http://www.aspenmedisys.com/nike-roshe-run-floreale-print-arancia-scarpei">nike roshe run floreale print arancia</a> <a href="http://www.smartiesland.com/nike-air-max-nero-hyperfuse-scarpeh">nike air max nero hyperfuse</a> <a href="http://www.emcetolerie.com/miami-marlins-new-era-2018-mlb-stars-and-stripes-39thirty-cap-hath">miami marlins new era 2018 mlb stars and stripes 39thirty cap</a> <a href="http://www.lapaktoko.com/hommes-nike-blazer-rose-violet-chaussuresh">hommes nike blazer rose violet</a>
[url=http://www.ikmsdkravmaga.com/]ikmsdkravmaga[/url]
maplebeyond
 maplebeyond 2019-05-20 03:00回复
#201
<a href="http://www.tmzred.com/nike-zoom-pegasus-34-gituttio-arancia-scarpel">nike zoom pegasus 34 gituttio arancia</a> <a href="http://www.alcovozov.com/nike-roshe-black-hyper-punch-white-shoesj">nike roshe black hyper punch white</a> <a href="http://www.ahmztradefx.com/herre-nike-air-huarache-light-appelsin-lyser%C3%B8d-skok">herre nike air huarache light appelsin lyser酶d</a> <a href="http://www.isampled.com/air-jordan-retro-29-hvit-oransje-obuvp">air jordan retro 29 hvit oransje</a> <a href="http://www.aldervets.com/nike-air-max-90-carved-silver-white-shoesi">nike air max 90 carved silver white</a> <a href="http://www.vanltl.com/air-jordan-retro-13-kvinders-gul-lyser%C3%B8d-skoj">air jordan retro 13 kvinders gul lyser酶d</a>
maplebeyond http://www.maplebeyond.com/
qtnkxrcr
 qtnkxrcr 2019-05-19 02:09回复
#200
<a href="http://www.bazicloob.com/nike-air-black-and-white-huarache-shoesj">nike air black and white huarache</a> <a href="http://www.malatyabolge.com/air-jordan-retro-4-silver-shoesl">air jordan retro 4 silver</a> <a href="http://www.impeachjohn.com/polo-ralph-lauren-red-canvas-duffle-bag-poloh">polo ralph lauren red canvas duffle bag</a> <a href="http://www.dafuqstory.com/air-jordan-retro-3.5-gr%C3%A5-sort-skok">air jordan retro 3.5 gr氓 sort</a> <a href="http://www.liberezmoi.com/herren-nike-air-force-1-olympic-grau-orange-schuheh">herren nike air force 1 olympic grau orange</a> <a href="http://www.scrutinit.com/nike-air-max-97-grey-red-shoesk">nike air max 97 grey red</a>
qtnkxrcr http://www.qtnkxrcr.com/
cumjacket
 cumjacket 2019-05-15 07:54回复
#199
<a href="http://www.antalyaritim.com/nike-flyknit-trainer-sort-gr%C3%A5-scarpef">nike flyknit trainer sort gr氓</a> <a href="http://www.wcscwoodlands.com/adidas-protator-lz-2-line-kurpesb">adidas protator lz 2 line</a> <a href="http://www.nchfnj.com/nike-roshe-negro-oreo-zapatosk">nike roshe negro oreo</a> <a href="http://www.unchartedlust.com/adidas-protator-futsal-rosa-runningc">adidas protator futsal rosa</a> <a href="http://www.bethelpipe.com/adidas-eqt-support-ultra-pk-gris-pattern-zapatosj">adidas eqt support ultra pk gris pattern</a> <a href="http://www.ftorrentz.com/dam%C3%A4nner-air-jordan-retro-3-gold-schwarz-chaussuresa">dam盲nner air jordan retro 3 gold schwarz</a>
cumjacket http://www.cumjacket.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸