Daily required javascript operators, javascript Operators

Source: Internet
Author: User

Daily required javascript operators, javascript Operators

Dear readers, I have already probably understood the role of Javascript and some basic function declaration and variable declaration. Today we will continue to explain the previous content, let's take a look at the logic (Forward order, branch, loop) of javscript and some simple operators.

The following are 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 before a number to mark it as a negative number.
  • * Multiplication: used to calculate the product of multiplication of two numbers.
  • /Division: used to calculate the operator obtained after division by Division
  • % Remainder: used to calculate the remainder obtained after the division by the Division (here the calculation is the Division, and the remainder after the division is obtained)
  • = Value assignment: used to assign a value (which can be an object, function, number, string, or Boolean) to a variable.

Here, we can clearly see that the operator shows the result of the operation, and I don't have to go into details after addition, subtraction, multiplication, division, and so on. I believe everyone's computation can be better than mine, because I just graduated from middle school, I want to talk a little more about the remainder operation. As shown in the example above, 5% 2 gets the remainder 1, which is calculated in this way. 5 then 2 = 2 ...... 1. I should have seen the calculation in the second grade of primary school. The Division by divisor = Operator ...... Remainder. This remainder is the result of the remainder operation. It is also the equivalent symbol that was mentioned yesterday. It is the var temp = value used for value assignment. We use the var keyword to declare the variable, use = to assign a value to you. The value type can be object, function, number, string, or Boolean. I already told you what the function is, it is a function body declared by the function, that is, a function. Needless to say, a string contains a string and a Boolean value in quotation marks, that is, there is only one type of two values, true and false, and there is no third type.

Next, let's take a look at the various values.

// Here we give an empty object (null) var temp_1 = null; // here we give a function var temp_2 = function () {console. log ("Write Something") ;}; // here we provide a string var temp_3 = "My name is MrDream "; // here we provide a boolean value var temp_4 = true;

These basic operations should be clear to everyone. If you want your readers to see these basic things, don't worry about them now. Now we are still in the initial introduction stage, everyone must understand that I will talk about more things in later articles. Otherwise, the Foundation will not be good. Later, when I talk about something that you will feel awesome, if you can only copy the code for use, it is meaningless and you cannot write something you want.

Next, let's take a closer look at what the minor upgrade of operators will look like? (Note: currently, I only talk about some basic operators and some special operators. I will explain them later in some applications, so that I can understand them more deeply)

  • + = Addition: adds two operation objects first, and then assigns the added value to the first operation object.
  • -= Subtraction: Perform the subtraction operation on the two operation objects first, and then assign the added value to the first operation object.
  • * = Multiplication: multiply two operation objects first, and then assign the added value to the first operation object.
  • /= Division: first divide the two operation objects, and then assign the added value to the first operation object.
  • % = Remainder: Perform the remainder operation on the two operation objects, and then assign the added value to the first operation object.

Some comparison Operators

  • = Equals: determines 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 objects on both sides of the operator are absolutely not equal
  • ! = Not equal to: determines whether the objects on both sides of the operator are not equal
  • | Or: first, determine whether the objects on both sides of the operator are "non-empty objects or non-undefined objects". If both are, return the right value, if there is a value that is not, it will return a value that is not
  • & And (and): first, determine whether the objects on both sides of the operator are "non-empty objects or non-undefined objects". If neither of them is true, return the right value, if one value is yes, the value is returned. If both are, the value on the left is returned.
  • ! Inverse (not): convert a value to a Boolean value, and then obtain the inverse value.

(Note: here we mention the OR, and, taking the Inverse Operator, I use the general understanding logic to talk about it. In fact, internal operations, is the result of binary or non-operation. We will discuss it in detail when talking about binary.) Let's look at some examples below.

Next we will talk about one or more non-operations, and it will be a little more difficult to understand.

As shown in the figure, A returns the right value because no object is defined on the left of the operator. B returns the right value because the left side is an empty object. C, because there is a real number 123 on the left, 123 is returned. D returns the value on the left because the real value is-1 on the left. Add one: The number 0 is also a special value. If the value on the left is 0, the right value is returned.

Conclusion or operator: it is used to check whether there are undefined values, null values, 0 and false on both sides of the operator. If there are these values on the left, the value on the right is returned, if the value is not of these types on the left, the value on the left is returned.

Subsequent operations

Still look at the figure, where A is: The left and right are undefined objects and empty objects respectively, return the value on the left; B is empty objects on the left, so return to the left; C: Undefined objects on the right, so return the right value; D: The same as C; E: both are non-empty objects; the Boolean value on the left is true, so return the right; F and E are the same; g: The left side is 0, which is the same as the undefined object, null object, and false. Therefore, the left side is returned.

The last one is non-operation.

Continue to look at the figure. A: The operation is 0, false, null, undefined, and so on. The return operation gets the true value of the Boolean value. B: It is A reverse operation on the actual value, the primary value is a Boolean value of false. We can sum up that the reverse result is a Boolean value. The reverse result of an actual value is correct, and the reverse result of the actual value is an error.

Well, I will write it here today. To sum up, today we actually talk about some basic operators, but the number of operators is a bit large, so I wrote this right, we can only express it. There are some special operators. We will talk about it later, as long as we make a little progress every day, it is not a dream to achieve a great generation of gods.

Articles you may be interested in:
  • Js and or operator |
  • JS by-bit non (~) Operators and ~~ Understanding and Analysis of Operators
  • Summary of common operators in JavaScript
  • Introduction to using boolean operators in js
  • Bitwise anti-operator in Javascript (~)
  • Introduction to the bitwise left Shifting Operator in Javascript (<)
  • Usage record of operators & | in js
  • Summary of six operators in JavaScript
  • Differences between the three-object operator and if else in JS
  • Example of javascript ternary operator usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.