色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

javascript 運(yùn)算符

JavaScript是一門腳本語(yǔ)言,通常被用于網(wǎng)頁(yè)客戶端腳本編程。在JavaScript中,運(yùn)算符是一種用來(lái)執(zhí)行數(shù)學(xué)或者邏輯操作的特定標(biāo)記。本文將詳細(xì)介紹JavaScript中的運(yùn)算符。
1. 算術(shù)運(yùn)算符 算術(shù)運(yùn)算符用于執(zhí)行算術(shù)操作,比如加、減、乘、除等。下面是一些常用的算術(shù)運(yùn)算符的示例:
var a = 10;
var b = 2;
<br>
document.write("a + b = " + (a + b) + "<br>");
document.write("a - b = " + (a - b) + "<br>");
document.write("a * b = " + (a * b) + "<br>");
document.write("a / b = " + (a / b) + "<br>");
document.write("a % b = " + (a % b) + "<br>");
以上示例中,變量a和b分別為10和2,打印了它們的加、減、乘、除和取模(即取余數(shù))運(yùn)算結(jié)果。
2. 邏輯運(yùn)算符 邏輯運(yùn)算符用于執(zhí)行邏輯操作,比如與、或、非等。下面是一些常用的邏輯運(yùn)算符的示例:
var a = true;
var b = false;
<br>
document.write("a && b = " + (a && b) + "<br>");
document.write("a || b = " + (a || b) + "<br>");
document.write("!a = " + (!a) + "<br>");
document.write("!b = " + (!b) + "<br>");
以上示例中,變量a和b分別為true和false,打印了它們的與、或和非運(yùn)算結(jié)果。
3. 比較運(yùn)算符 比較運(yùn)算符用于比較兩個(gè)值是否相等或大小關(guān)系。下面是一些常用的比較運(yùn)算符的示例:
var a = 10;
var b = 5;
<br>
document.write("a == b is " + (a == b) + "<br>");
document.write("a != b is " + (a != b) + "<br>");
document.write("a > b is " + (a > b) + "<br>");
document.write("a < b is " + (a < b) + "<br>");
document.write("a >= b is " + (a >= b) + "<br>");
document.write("a <= b is " + (a <= b) + "<br>");
以上示例中,變量a和b分別為10和5,打印了它們的相等、不相等、大于、小于、大于等于和小于等于運(yùn)算結(jié)果。
4. 賦值運(yùn)算符 賦值運(yùn)算符用于給變量賦值。下面是一些常用的賦值運(yùn)算符的示例:
var a = 10;
var b = 5;
<br>
a += b;
document.write("a += b is " + a + "<br>");
<br>
a -= b;
document.write("a -= b is " + a + "<br>");
<br>
a *= b;
document.write("a *= b is " + a + "<br>");
<br>
a /= b;
document.write("a /= b is " + a + "<br>");
<br>
a %= b;
document.write("a %= b is " + a + "<br>");
以上示例中,變量a和b分別為10和5,執(zhí)行了加、減、乘、除和取模賦值運(yùn)算。
5. 位運(yùn)算符 位運(yùn)算符用于對(duì)二進(jìn)制位進(jìn)行操作。下面是一些常用的位運(yùn)算符的示例:
var a = 10;
var b = 5;
<br>
document.write("(a & b) = " + (a & b) + "<br>");
document.write("(a | b) = " + (a | b) + "<br>");
document.write("(a ^ b) = " + (a ^ b) + "<br>");
document.write("(~a) = " + (~a) + "<br>");
document.write("(a << 1) = " + (a << 1) + "<br>");
document.write("(a >> 1) = " + (a >> 1) + "<br>");
document.write("(a >>> 1) = " + (a >>> 1) + "<br>");
以上示例中,變量a和b分別為10和5,執(zhí)行了按位與、按位或、按位異或、取反、左移、右移以及無(wú)符號(hào)右移運(yùn)算。
總結(jié):本文詳細(xì)介紹了JavaScript中常用的運(yùn)算符,包括算術(shù)運(yùn)算符、邏輯運(yùn)算符、比較運(yùn)算符、賦值運(yùn)算符和位運(yùn)算符等。每個(gè)運(yùn)算符都有自己的規(guī)則和用法,開發(fā)者可以根據(jù)需要選擇適合的運(yùn)算符,進(jìn)行相關(guān)的數(shù)學(xué)或者邏輯操作。