Detailed explanation of js expressions and operator examples

小云云
Release: 2018-03-19 17:21:32
Original
1448 people have browsed it


This article mainly shares with you detailed explanations of js expressions and operator examples, hoping to help everyone.

js Expressions and Operators

1. Expressions

Expressions are formulas used for calculations when JavaScript scripts are running, and can include constants, variables, and operations. Operator;

2. Operator

Arithmetic operator

+-*/% ++ --

Note: Numeric types support increment and decrement operators, Boolean types support increment and decrement operators, strings do not support increment and decrement operators, null supports increment and decrement, undefined does not support

Character connector

The + sign is used to connect two strings;

As long as one of the + connection operands is a string type, js will automatically convert the non-string into a string type for processing ;

The order of js code execution is from left to right, so in the + expression, before string data is encountered, all numerical data that appears (or can be converted into numerical strings) is still is treated as a numerical value. In order to avoid this situation, we can add an empty string;

Assignment operator

=, +=, -+, * =, /=, %=

+= can be used to connect strings;

Comparison operators

==, ===, 》=,《=,! =,! ==

The result of comparison operator is Boolean;

== only compares the values for equality, === compares

Logical operator

&&, ||,!

&&: If the first result is false and the entire expression is false, the second one is short-circuited.

&&: There must be two expressions, and both expressions are true, then the result is true;

||: If one of the two expressions is true, the result is True;

||: If the first expression is true, the entire result is true, short-circuiting the second expression;

Ternary operator

exp1? exp2: exp3;

Other operators

Comma operator: Comma is used to connect multiple expressions into one expression, and the value of the new expression is the last The value of an expression is mostly used in variable declarations;

var z=(a=1,b=2,c=3);

then z=3; take the last expression The value of the expression;

void operator: The void operator is used to indicate that an expression has no return result;

var z=void(a=1,b=2,c=3) ;

alert(z);

then returns undefined

typeof operator: The typeof operator is used to return a string and the data type of the operand;

Detect variable type;

3. Operator priority

Related recommendations:

Detailed explanation of js expressions and operator codes

The above is the detailed content of Detailed explanation of js expressions and operator examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!