Table of Contents
Arithmetic Operators
算术运算符
Assignment Operators
赋值运算符
Comparison Operators
比较(关系)运算符
Logical Operators
逻辑运算符
String Operator
串符(连接作用)
Conditional Operator
条件运算符
Syntax
语法
Example
例子
Home Web Front-end JS Tutorial JS operator organization [recommended collection]_Basic knowledge

JS operator organization [recommended collection]_Basic knowledge

May 16, 2016 pm 05:59 PM
Operator

Arithmetic Operators
算术运算符

Operator Description Example Result
+ Addition
x=2
y=2
x+y
4
- Subtraction
x=5
y=2
x-y
3
* Multiplication
x=5
y=4
x*y
20
/ Division
15/5
5/2
3
2.5
% Modulus (division remainder)
余数
5%2
10%8
10%2
1
2
0
++ Increment
递增
x=5
x++
x=6
-- Decrement
递减
x=5
x--
x=4

Assignment Operators
赋值运算符

Operator Example Is The Same As
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
%= x%=y x=x%y

Comparison Operators
比较(关系)运算符

Operator Description Example
== is equal to
等于
5==8 returns false
=== is equal to (checks for both value and type)
等于(检查值和类型)*全吻合才算相等
x=5
y="5"

x==y returns true
x===y returns false

!= is not equal
不等于
5!=8 returns true
> is greater than
大于
5>8 returns false
< is less than
小于
5<8 returns true
>= is greater than or equal to
大于等于
5>=8 returns false
<= is less than or equal to
小于等于
5<=8 returns true

Logical Operators
逻辑运算符

Operator Description Example
&& and
x=6
y=3

(x < 10 && y > 1) returns true

|| or
x=6
y=3

(x==5 || y==5) returns false

! not
x=6
y=3

!(x==y) returns true

String Operator
串符(连接作用)

A string is most often text, for example "Hello World!". To stick two or more string variables together, use the + operator.
在文字当中使用的比较多,举例来说“Hello World!”要将两个或多个字符串变量衔接在一起的话就得使用 + 符号

txt1="What a very"
txt2="nice day!"

txt3=txt1+txt2 
Copy after login

The variable txt3 now contains "What a verynice day!".
txt3变量现在包含“What a verynice day!”(把1和2衔接起来了)

To add a space between two string variables, insert a space into the expression, OR in one of the strings.
要给两个字符串变量中间添加空格就得在表达式里插入空格,或在其中的一个加上(空格)

txt1="What a very"
txt2="nice day!"
txt3=txt1+" "+txt2
Copy after login
or
Copy after login
txt1="What a very "
txt2="nice day!"
txt3=txt1+txt2
Copy after login

The variable txt3 now contains "What a very nice day!".
现在变量txt3为“What a very nice day!”

Conditional Operator
条件运算符

JavaScript also contains a conditional operator that assigns a value to a variable based on some condition.
JS有根据条件不同给变量不同值的条件运算符

Syntax
语法

variablename=(condition)?value1:value2 
Copy after login

Example
例子

greeting=(visitor=="PRES")?"Dear President ":"Dear "
Copy after login

If the variable visitor is equal to PRES, then put the string "Dear President " in the variable named greeting. If the variable visitor is not equal to PRES, then put the string "Dear " into the variable named greeting.
如果变量visitor的值等于PRES那么greeting的值就为"Dear President "。如果不为PRES那么greeting的值就为"Dear"

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1237
24
Eight mysterious uses of the '!' operator in Linux commands Eight mysterious uses of the '!' operator in Linux commands Jun 27, 2023 pm 12:51 PM

Usage of most Linux commands using the '!' symbol may vary in different shells. While the examples I provide are typically used in bash shells, some other Linux shells may have different implementations or may not support certain uses of the '!' symbol at all. Let’s dive into the surprising and mysterious uses of the ‘!’ symbol in Linux commands. 1. Use the command number to run a command from the history. What you may not know is that you can run a command from the command history (commands that have already been executed). First, find the number of the command by running the 'history' command. linuxmi@linuxmi:~/www.linuxmi.

Learn more about the usage of the modulo equal operator in PHP Learn more about the usage of the modulo equal operator in PHP Mar 19, 2024 pm 12:54 PM

The modulo equal operator (%) is a very commonly used operator in PHP and is used to calculate the remainder of the division of two numbers. In this article, we will take an in-depth look at the usage of the modular equals operator and provide specific code examples to help readers better understand. First, let's look at a simple example. Suppose we need to calculate the remainder of dividing one number by another: $a=10;$b=3;$remainder=$a%$b;echo&quot;10 divided by 3 The remainder is: &amp;

sql in operator usage sql in operator usage Aug 04, 2023 pm 03:58 PM

SQL in operator usage: 1. Single column matching, you can use the IN operator to match multiple values ​​in a column; 2. Multi-column matching, the IN operator can also be used to match values ​​in multiple columns; 3. Subquery, The IN operator can also be used with a subquery, which is a query statement nested within the main query.

In C/C++, what is the meaning of operator c=a+++b? In C/C++, what is the meaning of operator c=a+++b? Sep 01, 2023 pm 04:29 PM

Let us consider that in C or C++, there is a similar statement: c=a+++b; So what is the meaning of this line of code? Okay, let a and b be 2 and 5 respectively. This expression can be viewed as two different types. c=(a++)+bc=a+(++b) has post-increment operator and pre-increment operator. How they are used depends on how they are used. There are two basic concepts. Priority and associativity. Now if we check the expression from left to right, the result will be these two. c=(a++)+b→2+5=7c=a+(++b)→2+6=8 Now let’s check which option is selected by the compiler - example code #include<io

Two new operators added to php7: '?->' and '??' Two new operators added to php7: '?->' and '??' Mar 21, 2023 pm 03:49 PM

In previous PHP versions, if we did not define a variable, using it directly would result in an Undefined variable error. However, in PHP7, we can use some new features to avoid this problem. These new features include two new operators: ?-> and ??. They can solve two different types of problems respectively.

How does the new operator work in js? How does the new operator work in js? Feb 19, 2024 am 11:17 AM

How does the new operator in js work? Specific code examples are needed. The new operator in js is a keyword used to create objects. Its function is to create a new instance object based on the specified constructor and return a reference to the object. When using the new operator, the following steps are actually performed: create a new empty object; point the prototype of the empty object to the prototype object of the constructor; assign the scope of the constructor to the new object (so this points to new object); execute the code in the constructor and give the new object

How to solve PHP error: Invalid operator? How to solve PHP error: Invalid operator? Aug 25, 2023 pm 02:21 PM

How to solve PHP error: Invalid operator? When developing and maintaining PHP projects, we often encounter various errors, one of which is "Invalid operator". This error usually indicates that an invalid operator is used in the code, causing PHP to be unable to correctly recognize and perform the corresponding operation. This article will introduce several common situations that cause this error and provide corresponding solutions. Using the wrong operator When writing PHP code, you may accidentally use the wrong operator, resulting in

Uncovering the secrets of Python syntax: from novice to master Uncovering the secrets of Python syntax: from novice to master Feb 20, 2024 pm 09:24 PM

Basic syntax python is an interpreted language with dynamic typing and garbage collection. Basic syntax includes: Data types: Python's built-in data types include integers, floating point numbers, strings, lists, tuples, and dictionaries. Variable: Use = to assign value. The variable name must start with a letter or underscore. It can contain numbers but cannot start with numbers. Operators: arithmetic, comparison, logical and bitwise operators. Flow control Python uses indentation to control the execution of code blocks: if-elif-else: conditional judgment statement. while: Loop statement, if the condition is true, the loop continues. for: iterative statement to traverse the elements in the sequence. break: Break out of the loop. Function A function is a syntax structure that encapsulates a block of code and can be reused.

See all articles