温水煮青蛙是什么意思| 眼底出血用什么眼药水最好| 吃什么长指甲最快| 偶像是什么意思| 脾阳不足吃什么中成药| 十年大运是什么意思| 更年期吃什么食物好| 经常吃秋葵有什么好处| 医师是什么级别| 查甲状腺应该挂什么科| 七点到九点是什么时辰| poems综合征是什么病| 百草枯是什么| 骨质增生是什么症状| 正常龟头什么样子| 细菌性阴道炎用什么药好得快| 梦见蛇被别人打死是什么兆头| 打冷是什么意思| 一倍是什么意思| 为什么会得灰指甲| 腰椎退行性改变什么意思| 增强胃动力吃什么药| 重塑是什么意思| 陷阱是什么意思| 为什么一吃饭就拉肚子| 老是打哈欠是什么原因| prp是什么| 穆萨是什么意思| 氯喹是什么药| 宫颈纳氏囊肿是什么| 长期手淫有什么危害| 也字少一竖念什么| 什么体质容易长结石| 违和是什么意思| 纯粹什么意思| 睡觉食管反流什么原因| 黑色水笔是什么笔| 鲨鱼用什么呼吸| 决明子是什么| 月经结束一周后又出血是什么原因| 小脑梗塞会出现什么症状| 内分泌失调吃什么食物好| 深覆合是什么样子的| 人流后吃什么药| 榴莲不能和什么吃| 狐狸的尾巴有什么作用| 什么问题| maxco是什么牌子| 维c吃多了有什么副作用| 麦冬有什么功效| 奥美拉唑是治什么病的| 皮内瘤变到底是什么意思| 脑梗前期有什么症状| 考科目二紧张吃什么药| 亨字五行属什么| 六神无主是什么意思| 什么时候种白菜| 世界上最难的数学题是什么| 同比和环比是什么意思| 梦见撒尿是什么意思| 球蛋白低是什么原因| 双皮奶是什么| 皮实是什么意思| 西昌火把节是什么时候| 压力大会有什么症状| 早晚体重一样说明什么| 青榄配什么煲汤止咳做法| 凌空什么什么| 胃不好吃什么| 1月30号是什么星座| 跟单员是做什么的| 眼底出血有什么症状| 血小板减少有什么危害| 刚刚邹城出什么大事了| 草字头加弓念什么| nibp是什么意思| 泌尿外科看什么病| 忧心忡忡是什么意思| 酒花浸膏是什么| 双的反义词是什么| 仔细的什么| 心电图hr是什么意思| 高血糖是什么原因引起的| 昆山有什么好玩的地方| 什么的原始森林| 请多指教是什么意思| mico是什么意思| 疣长什么样子| 冰箱灯不亮是什么原因| 体育总局局长什么级别| 牛油果树长什么样| 渚是什么意思| 冬字五行属什么| 乳房边缘疼是什么原因| 阴枣是什么| 林深时见鹿是什么意思| 龟代表什么生肖| AMI是什么病| 吃虾不能和什么一起吃| 宫颈口在什么位置| 24D是什么激素| 恬静是什么意思| 移民瑞士需要什么条件| 千金是什么生肖| 落地生根是什么生肖| 侬是什么意思| 转折是什么意思| 飞克手表什么档次| 肛裂用什么药膏| 羟苯乙酯是什么东西| 女生什么时候是安全期| 移植后吃什么水果好| bra什么意思| 抗病毒什么药效果好| 什么叫惊喜| 胎盘低置是什么原因造成的| 手心脚心发热是什么原因| 喉咙干是什么病的前兆| 什么是水象星座| ct什么意思| 味增是什么| 可乐饼为什么叫可乐饼| 喝冰水牙疼是什么原因| 满是什么结构| 红楼梦又名什么| 葡萄糖阳性是什么意思| 点心是什么意思| 1号来月经什么时候是排卵期| 管科是什么专业| 麝是什么动物| oem是什么| 女人梦见自己掉牙齿是什么征兆| 防晒隔离什么牌子好| 腋臭是什么原因引起的| 籼米是什么米| 刘邦属什么生肖| 什么是量子力学| 男人要的归属感是什么| 美国现在什么季节| 端午节在什么时候| 上午十点多是什么时辰| 上火了吃什么降火最快| 肝做什么检查最准确| 胃酸吃什么食物好得快| 吃了虾不能吃什么| 希特勒为什么杀犹太人| 为什么会流鼻血什么原因引起的| 2.17是什么星座| 梦见好多羊是什么意思| 饮鸩止渴是什么意思| 浮瓜沉李什么意思| elephant什么意思| 孕妇心情不好对胎儿有什么影响| 李五行属性是什么| 海参有什么功效| foreverlove是什么意思| 端午节有什么活动| 肠胃功能紊乱什么症状| 13年属什么| 什么是水肿| 什么的阳光| 阳历12月是什么星座| 眼睑红是什么原因| 白参是什么参| 杀马特是什么意思| 廓清是什么意思| 战狼三什么时候上映| 为什么脚底会脱皮| 消化不良反酸吃什么药| 无名指和小指发麻是什么原因| 被隐翅虫咬了涂什么药| 腿外侧是什么经络| 的近义词是什么| 火加同念什么| 糖醋鱼用什么鱼| 易烊千玺是什么星座| 菠萝和凤梨有什么区别| 梦见买东西是什么意思| 苍蝇最怕什么| lily是什么牌子| 巴西龟吃什么食物| 味淋可以用什么代替| 请什么自什么| 夏的五行属什么| 集体户口是什么意思| 长期抽烟清肺喝什么茶| 吃什么水果补血| 人类什么时候出现的| 脚出汗多是什么原因怎么办| 脂溢性皮炎用什么洗发水| 前额头痛吃什么药| 为什么眼睛会有红血丝| 什么是病毒| 5月1号是什么星座| 什么是淋巴| 促什么谈什么| 香叶是什么树叶| 大枣吃多了有什么危害| 用白醋泡脚有什么好处| 手麻是什么原因引起| 代孕是什么意思| 玉帝和王母是什么关系| 行政助理是干什么的| 眼压高吃什么药| 意义是什么意思| 境遇是什么意思| 鼻涕有血丝是什么原因| 毒血症是什么病| 79是什么意思| 疱疹用什么药可以根治| 偏光镜什么意思| 大娘的老公叫什么| 医院可以点痣吗挂什么科| 217是什么意思| 巨细胞病毒igg阳性是什么意思| 焦油是什么| 日出扶桑是什么意思| 2020是什么生肖| 什么人不能吃芒果| 挛是什么意思| 外阴裂口用什么药| 普洱茶适合什么季节喝| 麻长什么样子图片| 1981年什么命| 补气血什么季节补最好| 为什么猫怕水| 男子精少吃什么药可以生精| 呕气是什么意思| 软卧代软座什么意思| 嘴唇红润是表示什么| 13点是什么意思| 大姨妈不来是什么原因造成的| 灭活是什么意思| 梦见和老公结婚是什么意思| 8000年前是什么朝代| 吃完饭就想睡觉是什么原因| 人走了说什么安慰的话| 身体年龄是什么意思| 白子是什么东西| 4.19是什么星座| 小孩阑尾炎是由什么原因引起的| 毛囊炎用什么药膏好| 苦丁茶有什么作用和功效| 肾造瘘是什么意思| 痘痘破了涂什么药膏| 1882年属什么生肖| 肠胃炎可以喝什么饮料| 口腔溃疡反反复复是什么原因| 验尿白细胞高是什么原因| 床上什么虫子夜间咬人| 80岁称什么之年| 私募是什么| 白细胞十一是什么意思| 腐男是什么意思| 为什么身体没力气也没有精神| 染指什么意思| 膜性肾病什么意思| 抗角蛋白抗体阳性是什么意思| 一什么树叶| 肛周脓肿吃什么消炎药| 肚子痛是什么原因| 强阳下降到什么程度开始排卵| 心脏窦性心律什么意思| 囊是什么结构| 百度Jump to content

跳蚤的天敌是什么

From Wikibooks, open books for an open world
百度   本月初,“中研院院士”廖运范、陈定信等人,连署建议“矫正署”尊重台中荣总医疗判断,让扁居家疗养;去年台北荣总也有类似建议,但“矫正署”考虑公平性,且监狱行刑法也没有“居家疗养”规定,始终不准,但努力让扁舍房,朝具备“居家疗养”条件的方向改善。



String concatenation

[edit | edit source]

The + operator acts in two different ways depending on the type of its two operands. If one or both of them are strings, it acts as a string concatenator. If both are numeric, it acts as an arithmetic addition.

An example of string concatenation is "one " + "world" resulting in "one world". If one of the two operands isn't a string, it is implicitly converted to a string before the + operation takes place.

"use strict";

// regular concatenation
const word_1 = "one";
const word_2 = "world";
let   result = word_1 + " " + word_2;
alert(result);        //  "one world"

// implicit type conversion
const arr = [41, 42, 43];
result = word_1 + arr + word_2;   // first, the array is converted to a string
alert(result);        //  "one41,42,43world"

// dito
const x = 1;
result = x + word_2;
alert(result);        //  "1world"

Arithmetic operators

[edit | edit source]

JavaScript has the arithmetic operators +, -, *, /, % (remainder), and ** (exponentiation). These operators work the way you learned in mathematics. Multiplication and division will be calculated before addition and subtraction. If you want to change such precedence, you can use parenthesizes.

Hint: In opposite to some other languages, the division operation may result in a floating point number - it's not always a pure integer.

const a = 12 + 5;       // 17
const b = 12 - 5;       // 7
const c = 12 * 5;       // 60
const d = 12 / 5;       // 2.4   Division results in floating point numbers
const e = 12 % 5;       // 2     Remainder of 12/5 is 2
const f = 12 - 2  * 5;  // 2     Multiplication is calculated first
const g =(12 - 2) * 5;  // 50    Parenthesis are calculated first

Some mathematical operations, such as dividing by zero, cause the returned variable to be one of the error values - for example, infinity, or NaN (Not a number).

The return value of the remainder operator maintains the sign of the first operand.

The + and - operators also have unary versions, where they operate only on one variable. When used in this fashion, + returns the number representation of the object, while - returns its negative counterpart.

"use strict";
const a = 42;
const b = +a;    // b is 42
const c = -a;    // c is -42

As noted above, + is also used as the string concatenation operator: If any of its arguments is a string or is otherwise not a number, all arguments are converted to strings and concatenated together. All other arithmetic operators works the other way round: They attempt to convert their arguments into numbers before evaluating.

"use strict";
const a = 42;
const b = "2";
const c = "3";
alert(a + b);   //  "422"  (a string)
alert(a * b);   //  84     (a number)
alert(b * c);   //  6      (a number)

Bitwise operators

[edit | edit source]

There are seven bitwise operators: &, |, ^, ~, >>, <<, and >>>.

These operators convert their operands to integers (truncating any floating point towards 0), and perform the specified bitwise operation on them. The logical bitwise operators, &, |, and ^, perform the and, or, and xor on each individual bit and provides the return value. The ~ (not operator) inverts all bits within an integer, and usually appears in combination with the logical bitwise operators.

Two bit shift operators, >>, <<, move the bits in one direction that has a similar effect to multiplying or dividing by a power of two. The final bit-shift operator, >>>, operates the same way, but does not preserve the sign bit when shifting.

These operators are kept for parity with the related programming languages, but are unlikely to be used in most JavaScript programs.

Assignment operators

[edit | edit source]

The assignment operator = assigns a value to a variable. Primitive types, such as strings and numbers, are assigned directly. However, function and object names are just pointers to the respective function or object. In this case, the assignment operator only changes the reference to the object rather than the object itself. For example, after the following code is executed, "0, 1, 0" will be alerted, even though array_A was passed to the alert, but array_B was changed. This is because they are two references to the same object.

"use strict";
const array_A = [0, 1, 2];
const array_B = array_A;
array_B[2] = 0;
alert(array_A);  // 0, 1, 0

Similarly, after the next code snippet is executed, x is a pointer to an empty array.

"use strict";
const z = [5];
const x = z;
z.pop();
alert (x);

If the result of any of the above-shown arithmetic or bitwise operators shall be assigned to its first operand, you can use a shorter syntax. Combine the operator, e.g., +, directly with the assignment operator = resulting in +=. As an example x = x + 5 can be abbreviated as x += 5.

The abbreviated operator/assignment syntax reads:

Arithmetic Logical Shift
+= &= >>=
-= |= <<=
*= ^= >>>=
/=
%=

For example, a common usage for += in a for loop:

"use strict";
const arr = [1, 2, 3];
let sum = 0;
for (let i = 0; i < arr.length; i++) {
  sum += arr[i];  // same as: sum = sum + arr[i];
}
alert(sum);

Increment operators

[edit | edit source]

Increment and decrement operators are a particular form of arithmetic operators: ++ and --. a++ increments a and returns the old value of a. ++a increments a and returns the new value of a. The decrement operator acts similarly but reduces the variable instead.

As an example, the next operations all perform the same task:

"use strict";
let a = 1;
alert(a);     // 1

a = a + 1;
alert(a);     // 2

a += 1;
alert(a);     // 3

a++;
alert(a);     // 4

++a;
alert(a);     // 5

// but this SHOWS something different; see next chapter
alert(a++);   // shows 5 again
alert(a);     // nevertheless, 'a' was incremented to 6

Pre and post-increment operators

[edit | edit source]

Increment operators may be written before or after a variable. The position decides whether they are pre-increment or post-increment operators, respectively. That affects the operation.

"use strict";

// increment occurs before a is assigned to b
let a = 1;
let b = ++a;  // a = 2, b = 2;

// increment occurs to c after c is assigned to d
let c = 1;
let d = c++;  // c = 2, d = 1;

Due to the possibly confusing nature of pre and post-increment behavior, code can be easier to read if you avoid increment operators.

"use strict";

// increment occurs before a is assigned to b
let a = 1;
a += 1;
let b = a;  // a = 2, b = 2;

// increment occurs to c after c is assigned to d
let c = 1;
let d = c;
c += 1;     // c = 2, d = 1;

Comparison operators

[edit | edit source]

Comparison operators determine whether their two operands meet the given condition. They return true or false.

Concerning the 'equal' and 'not-equal' operators, you must take care. == is different from ===. The first one tries to adapt the data type of the two types to each other and then compares the values. The second one compares the types as well as their values and returns only true if type and value are identical: 3 == "0003" is true and 3 === "3" is false.

Op. Returns Notes
== true, if the two operands are equal May change an operand's type
(e.g. a string as an integer).
=== true, if the two operands are strictly equal Does not change operands' types.
Returns true if they are the same type and value.
!= true, if the two operands are not equal May change an operand's type
(e.g. a string as an integer).
!== true, if the two operands are not strictly equal Does not change the operands' types.
Returns true if they differ in type or value.
> true, if the first operand is greater than the second one
>= true, if the first operand is greater than or equal to the second one
< true, if the first operand is less than the second one
<= true, if the first operand is less than or equal to the second one

We recommend using the strict versions (=== and !==) because the simple versions may lead to strange and non-intuitive situations, such as:

0 == ''            // true
0 == '0'           // true
false == 'false'   // false (''Boolean to string'')
false == '0'       // true  (''Boolean to string'')
false == undefined // false
false == null      // false (''Boolean to null'')
null == undefined  // true

... although you might want:

0 === ''            // false
0 === '0'           // false
false === 'false'   // false
false === '0'       // false
false === undefined // false
false === null      // false
null === undefined  // false

Logical operators

[edit | edit source]

The logical operators are and, or, and not — written as &&, ||, and !. The first two take two boolean operands each. The third takes one and returns its logical negation.

Operands are boolean values or expressions that evaluate to a boolean value.

"use strict";
const a = 0;
const b = 1;

if (a === 0 && b === 1) {  // logical 'and'
  alert ("a is 0 AND b is 1");
}

if (a === 1 || b === 1) {  // logical 'or'
  alert ("a is 1 OR b is 1");
}

&& and || are short circuit operators: if the result is guaranteed after the evaluation of the first operand, it skips the evaluation of the second operand. Due to this, the && operator is also known as the guard operator, and the || operator is known as the default operator.

"use strict";

// declare 'myArray' without initialization
let myArray;

// runtime error!
if (myArray.length > 0) {
  alert("The length of the array is: " + myArray.length);
}

// no error because the part after '&&' will not be executed!
if (myArray && myArray.length > 0) {
  alert("The length of the array is: " + myArray.length);
}

The ! operator determines the inverse of the given boolean value: true becomes false and false becomes true.

Note: JavaScript represents false by either a Boolean false, the number 0, NaN, an empty string, or the built-in types undefined or null. Any other value is treated as true.

Concerning the precedence of the three operators, ! is evaluated first, followed by &&, and lastly ||.

      a  ||   b  &&   !c

    |       |       |    |
    |       |       └ 1. ┘
    |       └───── 2. ───┘
    └───────── 3. ───────┘

More details on the relationship between precedence and short-circuiting are explained at MDN

Other operators

[edit | edit source]

The ? : operator (also called the "ternary" operator) is an abbreviation of the if statement. First, it evaluates the part before the question mark. Then, if true, the part between the question mark and the colon is evaluated and returned, else the part behind the colon.

const target = (a == b) ? c : d;

However, be careful when using it. Even though you can replace verbose and complex if/then/else chains with ternary operators, it may not be a good idea to do so. You can replace

if (p && q) {
    return a;
} else {
    if (r != s) {
        return b;
    } else {
        if (t || !v) {
            return c;
        } else {
            return d;
        }
    }
}

with

return (p && q) ? a
  : (r != s) ? b
  : (t || !v) ? c
  : d

The above example is a poor coding style/practice. When other people edit or maintain your code, (which could very possibly be you,) it becomes much more difficult to understand and work with the code.

Instead, it is better to make the code more understandable. Some of the excessive conditional nesting can be removed from the above example.

if (p && q) {
    return a;
}
if (r != s) {
    return b;
}
if (t || !v) {
    return c;
} else {
    return d;
}

delete

[edit | edit source]

delete obj.x unbinds property x from object obj.

The delete keyword deletes a property from an object. It deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.

new cl creates a new object of type cl. The cl operand must be a constructor function.

instanceof

[edit | edit source]

o instanceof c tests whether o is an object created by the constructor c.

typeof

[edit | edit source]

typeof x returns a string describing the type of x. Following values may be returned.

Type returns
boolean "boolean"
number "number"
string "string"
function "function"
undefined "undefined"
null "object"
others (array, ...) "object"

Exercises

[edit | edit source]
... are available on another page (click here).

See also

[edit | edit source]
好无奈是什么意思 口苦吃什么药好 藕带是什么 黄鳝不能和什么一起吃 昕字取名什么寓意
一什么黑暗 重返20岁韩国版叫什么 哺乳期感冒吃什么药不影响哺乳 肺纤维化是什么病 你喜欢我什么我改
胆固醇过高有什么危害 梦见死人是什么征兆 本加一笔是什么字 hpv45型阳性是什么意思 2000年什么年
肠胃不好吃什么水果比较好 做梦梦到蜈蚣是什么意思 芼什么意思 kgs是什么单位 穿孔是什么意思
部长助理是什么级别hcv8jop6ns7r.cn 章鱼吃什么食物hcv8jop6ns8r.cn 脚抽筋吃什么药hcv7jop7ns0r.cn guou是什么牌子的手表hcv9jop6ns5r.cn 智商高的人有什么特征hcv8jop4ns7r.cn
喝酒伤什么gysmod.com 软著是什么hcv8jop8ns0r.cn 脸发红发烫是什么原因hcv9jop6ns9r.cn 阴虱什么症状wuhaiwuya.com 七月五日是什么星座hcv9jop5ns9r.cn
贞操带是什么hcv8jop5ns2r.cn 怀孕了挂什么科hcv8jop9ns5r.cn 发烧喉咙痛吃什么药好hcv9jop3ns1r.cn 钾高吃什么药96micro.com 合胞病毒用什么药最好hcv8jop2ns1r.cn
牛蒡是什么hcv7jop7ns3r.cn 葛根是什么植物的根hlguo.com 什么水解酒inbungee.com 为什么晚上不能剪指甲jinxinzhichuang.com 县委办公室主任是什么级别hcv9jop4ns7r.cn
百度