JavaScript daily must-learn operator _javascript tips

Source: Internet
Author: User

Reader friends Good, I already have a general understanding of the role of JavaScript and some basic function declarations and variable declarations, today we will continue to explain the previous content, we will look at the logic of Javscript (positive sequence, Branch, loop) and some simple operators

Now let's talk about some simple operator operators

    • + Plus: 1. Used to calculate two numbers plus and 2. Used to splice two strings
    • -Minus sign: 1. Used to calculate the difference between two numbers, 2. Use a number to identify it as a negative
    • * Multiplication: Used to calculate the product of two numbers multiplying
    • /division: Used to compute the quotient of dividend divided by divisor
    • % remainder: Used to calculate the remainder of the dividend divided by divisor (where the calculation is divisible, the remainder is obtained)
    • = Assignment: To assign a value (which can be an object, function, number, String, Boolean) to a variable

Here, we can see clearly that the operator has shown the result of the operation, subtraction I do not have to repeat, I believe that everyone's calculation can be better than me, because I just graduated from high school, a little more to say is to take the rest of the operation, see the example above 5%2 take more than 1, is such a calculation, 5÷ 2 = 2 ... 1, the second grade in primary school should have seen the calculation bar, the divisor of the divisor = quotient ... The remainder, which is the result of the remainder operation, is the equivalent symbol that was mentioned yesterday, the var temp = value that is used to assign the value; We use the VAR keyword to declare variables, to give you a value, the value of the type can be objects, functions, numbers, strings, Boolean; we've already told you what a function is, a function that is declared by function, that is, the number, the string, A string of strings enclosed in quotes, a Boolean value that is a type with only two values, true and false, and no third.

Then let's take a look at the various values.

Here we give a null object (NULL)
  var temp_1 = null;
  Here we give a function
  var temp_2 = functions () {
   Console.log ("Write something");
  Here we give a string of
  var temp_3 = "My name is Mrdream";
  Here we give a Boolean value of
  var temp_4 = true;

These basic operations, we should be at a glance, hope that readers see these basics of things, now do not worry, now we are still in the introductory stage of introduction, so these basic things, we must understand, to the back of the article, I will speak more things, otherwise, the basis does not play well, behind, When I tell you something that you think is going to be a kick in the back, if you can just copy the code and use it, there's no point in writing something you want.

Let's take a closer look at what is the small upgrade of the operator? (Note: At present, I only say some basic operators, there are some special operators, I will explain in some applications later, the understanding is more profound)

    • + + ET: first two action objects are added, and then the added value to the first Operation object
    • -= minus: First, two action objects are subtracted and then the added value is assigned to the first action object
    • *= multiplication and so on: First, two action objects are multiplied, and then the added value of the values assigned to the first action object
    • /=: First, two operation objects are divided into operations, and then add the value of the values assigned to the first action object
    • %= Yu: First of the two operating objects to take the remainder of the operation, and then add the value after the first assignment to the object

And then some simple comparison with the judge operator

    • = = equals: Determines whether the objects on both sides of the operator are equal
    • = = = Absolute equals: Determine whether the objects on both sides of the operator are absolutely equal
    • !== is absolutely not equal to: Determine whether the objects on both sides of the operator are absolutely unequal
    • != is not equal to: Determine whether the objects on either side of the operator are unequal
    • || or (OR): First, determine whether the object on both sides of the operator is "Non-empty object or not undefined object", if two are all, return to the right for the value, if there is a value is not, return is not that value
    • && and (with): First of all, determine whether the object on both sides of the operator is "Non-empty object or not undefined object", if both are not, return to the right value, if there is a value is, return is that value, if two are, return to the left.
    • ! Reverse (non): Converts a value to a Boolean value and then the counter

(Note: Mentioned here or, and, take the inverse operator, I am using the general understanding of logic to speak, in fact, internal operations, is involved in the binary or with the result of the operation, we talk about the binary system in detail when we talk about the following we look at some examples

The following is a little or no operation, understanding on a little more difficult

Look at the picture speak, a, because the operator is not defined on the left, so return to the right side of the value, B, because the left is a null object, so return to the right side of the value; C, because the left has a real value of 123, so return to 123;d because the left is the real value of the number 1, so return to the left of the value. Add a: Number 0 is also a special value, if the left is 0, then the right is returned to the value.

Summary or the function of the operator: to see whether the operator left or right is undefined value, null value, 0,false, if the left is these values, return to the right-hand value, if the left side is not the value of these types, return the value on the left.

Then and the operation

Still looking at the diagram, a: the left and right are undefined objects and empty objects, return to the left of the value, B on the left is an empty object, so return to the left; C: Right is undefined object, so return to the right value; D: same as C; e: Both are Non-empty objects, the left Boolean is true, so return to the right F and the same with E; G: Because the left side is 0, with undefined objects, empty objects, and false peers, the left value is returned.

The last one is a non operation.

Continue to look at the picture speak, a: the operation is 0 false null undefined such a value, take back, you get the true;b of the Boolean value: all the real value of the reverse operation, the obtained main is a Boolean value false. We can conclude that the inverse of the obtained is a Boolean value, the actual value of the reverse is correct, the actual value of the reverse is wrong.

Okay, here's what we're going to write today, to sum up, today, actually also said some very basic operators, but the number of operators is a bit more, so it is still written so right, it will be expressed, there are some special operators, we later say, as long as a little progress every day, the achievement of a generation of great God is not a dream.

Related Article

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.