javascript - 怎么讓if和else同時(shí)執(zhí)行輸出console.log()
問(wèn)題描述
if(條件){console.log(’ab’) }else{console.log(’cd’) }條件這里可以添加任意代碼 最終結(jié)果是console.log(’abcd’) 辦法貌似有很多,但是好像很多人想到的是不能同時(shí)成立
問(wèn)題解答
回答1:if (條件) { console.log(’ab’)} else { console.log(’cd’)}
條件這里可以添加任意代碼最終結(jié)果是console.log(’abcd’)辦法貌似有很多,但是好像很多人想到的是不能同時(shí)成立
這不是我上次看 @南小鳥(niǎo) 的博客里面的問(wèn)題么。。
01 替換if (console.log(’abcd’), console.log = () => {}){ console.log(’ab’);} else { console.log(’cd’); }02 替換
if (console._log = console.log, console.log = str => console._log(str + ’cd’)){ console.log(’ab’);} else { console.log(’cd’); }03 bind
if (!( console.log = console.log.bind(console, ’ab’))){ console.log(’ab’);} else { console.log(’cd’); }
不過(guò)結(jié)果是 ’ab cd’ 多了個(gè)空格 ...
04 setTimeout + 替換if (setTimeout(console.log.bind(null, ’abcd’)), console.log = _ => _) { console.log(’ab’)} else { console.log(’cd’)}05 setTimeout + 清屏
if (setTimeout(_ => { console.clear(), console.log(’abcd’) })){ console.log(’ab’)} else { console.log(’cd’)}回答2:
。。。。。。。是我不理解你的需求 還是你缺乏基本的編程邏輯if else 是互斥的
回答3:ab abcd || cd abcd 邏輯上不存在同時(shí)出現(xiàn)
回答4:if(條件){ console.log(’ab’);}
if(另一個(gè)條件) { console.log(’cd’);}
if 和 else 只能運(yùn)行其中一個(gè)條件,如果if條件符合就不會(huì)運(yùn)行else
回答5:if(true){}else if(false){ console.log(’ab’)}else{ console.log(’cd’)}console.log(’abcd’)
簡(jiǎn)直腦經(jīng)急轉(zhuǎn)彎。。
回答6:if(console.log(’ab’)){ console.log(’ab’))}else{ console.log(’cd’)}回答7:
腦袋有問(wèn)題,哪個(gè)寫(xiě)到生產(chǎn)環(huán)境試試、而且同時(shí)執(zhí)行了么。。
回答8:看了采納的答案,首先問(wèn)題是說(shuō)同時(shí)執(zhí)行,都是曲線救國(guó)只為了輸出abcd做的哪里看出同時(shí)執(zhí)行了?
相關(guān)文章:
1. html5和Flash對(duì)抗是什么情況?2. html5 - datatables 加載不出來(lái)數(shù)據(jù)。3. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????4. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!5. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. javascript - QQ第三方登錄的問(wèn)題9. javascript - 在 model里定義的 引用表模型時(shí),model為undefined。10. spring-mvc - spring-session-redis HttpSessionListener失效

網(wǎng)公網(wǎng)安備