Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use arithmetic operator and assignment operator in JavaScript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use arithmetic operators and assignment operators in JavaScript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

JavaScript operator

The operator = is used for assignment. The operator = is used to assign values to JavaScript variables.

The operator + is used to add value. The arithmetic operator + is used to add up values.

Yoshimoto! 5tzentz! 2wittxposiyyogz!

Note: after the above statement is executed, the value of x is 7.

JavaScript arithmetic operator

Arithmetic operators are used to perform arithmetic operations between variables and / or values. Given yard5, there are:

X=y+2 / / + (plus) x=7x=y-2 / /-(minus) x=3x=y*2 / / * (multiply) x=10x=y/2 / (divide) x=2.5x=y%2 / /% (find the remainder) x=1x=++y / / + (accumulate) x=6x=--y /-- (decreasing) xQuest 4

JavaScript assignment operator

The assignment operator is used to assign values to JavaScript variables. Given xflux 10 and ytree 5, there are:

Xchangy / / = (equivalent to x=x+y) x=5x+=y / / + = (equivalent to x=x+y) x=15x-=y / /-= (equivalent to x=x-y) x=5x*=y / / * = (equivalent to x=x*y) x=50x/=y / = (equivalent to x=x/y) x=2x%=y / /% = (equivalent to x=x%y) xroom0

+ operator for strings

The + operator is used to add (concatenate) text values or string variables.

To concatenate two or more string variables, use the + operator.

Txt1= "What a very"; txt2= "nice day"; txt3=txt1+txt2

Note: after the above statement is executed, the variable txt3 contains a value of "What a verynice day".

Tip: to add a space between two strings, you need to insert the space into a string:

Txt1= "What a very"; txt2= "nice day"; txt3=txt1+txt2

Or insert spaces into the expression:

Txt1= "What a very"; txt2= "nice day"; txt3=txt1+ "" + txt2

Note: after the above statement is executed, the variable txt3 contains the value "What a very nice day"

Add strings and numbers

If you add a number to a string, the result becomes a string.

[xss_clean] (x); [xss_clean] (""); x = "5" + "5"; [xss_clean] (x); [xss_clean] ("); x xss_clean +" 5 "; [xss_clean] (x); [xss_clean] ("); x = "5" + 5; [xss_clean] (x); [xss_clean] (") This is the end of the article on "how to use arithmetic operators and assignment operators in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report