Home > Web Front-end > JS Tutorial > body text

Detailed graphic and text explanation of how to simply operate operators in javascript

伊谢尔伦
Release: 2017-07-19 09:31:02
Original
1315 people have browsed it

Let’s talk about some simple operation operators

  • + Plus sign: 1. Used to calculate the sum of two numbers , 2. Used to splice two strings

  • - Minus sign: 1. Used to calculate the difference between two numbers , 2. Used in front of a number to identify a negative number

  • ##* Multiplication sign: used to calculate the multiplication of two numbers Product

  • ##/ Division sign: used to calculate the quotient obtained after dividing the dividend by the divisor

  • % Remainder: used to calculate the remainder after dividing the dividend by the divisor (the calculation here is an integer division, and the remainder after integer division will be obtained)

  • = Assignment: used to assign a value (can be an object, function, number, string, Boolean) to a variable

Here, we can clearly see that the operators display the results of the operations. I don’t need to go into details about addition, subtraction, multiplication and division. I won’t go into details. I believe everyone’s calculation skills are better than mine, because I just graduated from middle school. What I want to talk about a little more is the remainder operation. See the above example of 5%2. The remainder is 1. It is calculated like this, 5 ÷ 2 = 2... 1, this calculation should have been seen in the second grade of elementary school, dividend ÷ divisor = quotient... remainder, this remainder is the result of the remainder operation, and it is also equal to what was mentioned yesterday The symbol is var temp = value used for assignment; we use the var keyword to declare variables, and = to assign values ​​to you. The type of the value can be an object, a function, a number, a string, or a Boolean; we have already told you about it before. , what a function is, is a function body declared with function, that is a function. Needless to say numbers, a string is a string of strings enclosed in quotation marks, and a Boolean value is a type with only two values. true and false, there is no third way.

Let’s take a look at what the various values ​​look like

//这里我们给了一个空对象(null)
  var temp_1 = null;
  //这里我们给一个函数
  var temp_2 = function(){
   console.log("Write Something");
  };
  //这里我们给了一个字符串
  var temp_3 = "My name is MrDream";
  //这里我们给了一个boolean值
  var temp_4 = true;
Copy after login

These basic operations should be clear to everyone. I hope readers can see these. When it comes to basic things, don’t be anxious now. We are still in the introductory stage, so everyone must understand these basic things. I will talk about more things in the following articles. Otherwise, the foundation will not be laid well. Later, when I talk about something that you think is awesome, it will be meaningless if you can only copy the code and use it, and you will not be able to write what you want independently.

Let’s further understand what the operator looks like after a small upgrade?

Note: At present, I only talk about some basic operators, and some special operators. I will explain them in some applications later, and then the understanding will be deeper

  • += Addition: First add the two operation objects, and then assign the added value to the first operation object

  • -= Subtraction: First subtract the two operands, and then assign the added value to the first operand

  • *= Multiply and wait: first multiply the two operation objects, and then assign the added value to the first operation Object

  • /= Division etc.: First divide the two operation objects, and then assign the added value Give the first operation object

  • %= remainder: first perform the remainder operation on the two operation objects, and then compare them The added value is assigned to the first operand

## and then some simple comparison operators

  • == Equal: Determine whether the objects on both sides of the operator are equal

  • # #=== Absolute equals: Determines whether the objects on both sides of the operator are absolutely equal
  • !== Absolute not equal: Determines whether the operator Whether the objects on both sides are absolutely not equal
  • != Not equal: Determine whether the objects on both sides of the operator are not equal
  • || Or (or): First determine whether the objects on the left and right sides of the operator are "non-null objects or non-undefined objects". If both If both are true, return the value on the right. If one value is not, return the value that is not that value
  • && And (AND): First determine whether the objects on the left and right sides of the operator are "non-null objects or non-undefined objects". If they are neither, return the right side value, if one value is yes, return the value that is yes, if both values ​​are yes, return the one on the left.

  • ! Negation (not): Convert a value to a Boolean value and then negate it

(Note: The or and negation operators mentioned here are explained using everyone’s common understanding of logic. In fact, the internal operation involves binary or The results produced by NAND operations will be discussed in detail when we talk about binary) Let’s look at some examples

The above is the detailed content of Detailed graphic and text explanation of how to simply operate operators in javascript. 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
Popular Tutorials
More>
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!