日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JavaScript中的If和Else语句(香草)

發布時間:2025/3/11 javascript 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JavaScript中的If和Else语句(香草) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Generally if statements have the following syntax:

通常, if語句具有以下語法:

if(condition){Our code;}

The condition, here can be anything from the mathematical expression, Boolean, relation operations etc.

條件,這里可以是數學表達式,布爾值,關系運算等中的任何一種。

In any case, the final value of any condition will either true or false. Once condition become true "Our code" will run that is in if block.

在任何情況下,任何條件的最終值都將為true或false。 條件變為真后,將運行if塊中的“我們的代碼” 。

Example 1:

范例1:

//condition: is 2 is less than 3? Yes so, condition = true if(2 < 3) {console.log("I am in if"); }

Output

輸出量

I am in if

Example 2:

范例2:

//400 is greater than 20 thus, condition = true if(400 > 20) {console.log("I am again in if block"); }

Output

輸出量

I am again in if block

Example 3:

范例3:

if(4-5+1 ==0) {console.log("Hey there I am back in if block"); }

Output

輸出量

Hey there I am back in if block

Note: We used == in condition instead of = because = is an assignment operator where as == is comparison operator is compares both operands and if they are equal then condition = true. Also != is a comparison operator which returns true if operands are not equal.

注意:我們在條件中使用==代替=,因為=是賦值運算符,其中==是比較運算符,它會比較兩個操作數,如果它們相等,則condition = true 。 !=也是比較運算符,如果操作數不相等,則返回true。

But, what if condition will be false then if block will not execute the code within its blocks, so how can we deal with it? Then we can use else statement,

但是,如果條件為假,那么如果塊將不執行其塊內的代碼,該怎么辦,那么我們該如何處理呢? 然后我們可以使用else語句,

if(false) {console.log("I am in if block"); } else {console.log("I am in ELSE block"); }

Output

輸出量

I am in ELSE block

Now, thing to keep in mind here is when if condition will be false then only else block will execute, and when if block will execute else block will not execute.

現在,要記住的是,如果條件為假,則只有else塊會執行,而如果如果block會執行,則else塊不會執行 。

When we need to check multiple conditions we can use multiple if statements,

當我們需要檢查多個條件時,可以使用多個if語句 ,

Example:

例:

let number = 12 if(number<20){console.log("condition 1 is true"); } if(number>20){console.log("condition 2 is true"); } if(number==12){console.log("condition 3 is true"); }

Output

輸出量

condition 1 is truecondition 3 is true .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}}

Alternatively, above code can be written using logical operators,

另外,也可以使用邏輯運算符編寫以上代碼,

Logical operators:

邏輯運算符:

&& (AND) and || (OR) are two logical operators which allow us to use multiple conditions using single if statement.

&& (AND)和|| (OR)是兩個邏輯運算符,可讓我們使用單個if語句使用多個條件。

With && (AND) it will be true when all conditions will true while in case of || (OR) it will be true even when any condition will be true out of all conditions.

使用&& (AND),在所有條件都為真的情況下為true,而在||的情況下,則為true (OR)即使所有條件中的任何條件都成立,也將成立。

Example:

例:

let num= 5if(num<6 && num>2){console.log("This will work"); } if(num<7 || num ==2){console.log("This will also work"); }

Here, both block will execute

在這里,兩個塊都將執行

嵌套if-else (Nested if-else)

Using nested if-else we can use check several cases, let us demonstrate nested if-else with following example:

使用嵌套的if-else我們可以使用check幾種情況,讓我們通過以下示例演示嵌套的if-else:

We generally use JS in Web application Development where we need to make decisions as per the situation. For example, let a user visits IncludeHelp website and that user want to comment on a discussion forum, but only registered user can comment on the forum, so How can we achieve this? Well, nested If and else can be use here.

我們通常在Web應用程序開發中使用JS,我們需要根據情況制定決策。 例如,讓用戶訪問IncludeHelp網站,而該用戶想在討論論壇上發表評論,但只有注冊用戶可以在該論壇上發表評論,那么我們如何實現此目的? 好吧, 嵌套的If and else可以在這里使用。

Example:

例:

var aboutVisitor = 'abc';if (aboutVisitor == 'user'){console.log("Comments Enable"); } else if (aboutVisitor == 'guest'){console.log("Comments Disable, view-only"); } else {console.log("Please Verify"); }

翻譯自: https://www.includehelp.com/code-snippets/if-and-else-statement-in-javascript-vanilla.aspx

總結

以上是生活随笔為你收集整理的JavaScript中的If和Else语句(香草)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲欧美综合一区 | 91av观看 | 狠狠干夜夜操 | 99精品视频在线观看免费 | 欧美激情一区二区三区四区 | 老司机深夜免费福利 | 国产成人精品aa毛片 | 国产激情片| 欧美亚州| 欧美透逼视频 | 99综合久久 | 久久98| 暴操白虎 | 欧美精品在欧美一区二区少妇 | 成人91免费 | 久久福利社 | 天天爽夜夜 | 国产suv精品一区二区883 | 日韩福利网| 最近免费中文字幕大全免费版视频 | 欧美一级淫片免费视频魅影视频 | 一区二区高清在线观看 | av片在线免费观看 | 深夜精品视频 | 少妇逼逼| 99re6在线| 大乳护士喂奶hd | 一区二区三区免费毛片 | 欧美一级一区二区三区 | 涩涩五月天| 日韩一区二区三区不卡 | 看片一区 | 日韩中文字幕一区二区三区四区 | 久久免费的精品国产v∧ | 亚洲精品第一页 | 9191在线视频 | 手机在线亚洲 | 亚洲欧美另类一区 | 亚洲一区在线视频 | 1级av| 日本久久视频 | 天天射天天干天天舔 | 森泽佳奈av | 国产又粗又猛又爽又黄的视频小说 | 日韩视频一区二区三区在线播放免费观看 | 比利时xxxx性hd极品 | 国精产品一区一区三区有限公司杨 | 免费看裸体网站视频 | 天天欧美 | 国家队动漫免费观看在线观看晨光 | av在线视| 日韩视频精品 | 日本女优网址 | 国产va亚洲va在线va | 69精品无码成人久久久久久 | 一区三区视频 | 欧美中文字幕一区二区三区 | 精品九九在线 | 一级中文片 | 99re视频精品| 中文字幕人妻一区二区三区 | 女裸全身无奶罩内裤内衣内裤 | 四虎成人影视 | 污污网站在线免费观看 | av在线三区 | 婷婷在线视频 | 色播99 | 人妻精品久久久久中文 | 中文在线观看免费 | 男女猛烈无遮挡免费视频 | 狠狠五月婷婷 | 91精品国自产在线偷拍蜜桃 | 成人3d动漫一区二区三区 | 牛牛电影国产一区二区 | 青青青在线视频 | 99久视频| 国产成人+综合亚洲+天堂 | 波多野结衣一二三区 | 精品一区二区三区国产 | 国产小视频在线观看免费 | 午夜av网址 | 日韩无码精品一区二区三区 | 久久久99精品| 欧美体内she精高潮 日韩一区免费 | 伊人春色在线 | 岳狂躁岳丰满少妇大叫 | 日韩女女同性aa女同 | 优优色影院 | 免费日韩毛片 | www.av日韩 | 四季av综合网站 | v99av| 亚洲国产三级 | 精品一区二区三区无码视频 | 亚洲私人影院 | 五月婷婷av| 理论片大全免费理伦片 | 性精品 | 天天免费看av |