JavaScript Advanced--(JS Basic grammar) Notes collation

Source: Internet
Author: User
Tags arithmetic operators logical operators ming

According to MU class network to learn to organize together notes, put things together look more convenient

What is a variable
The variable is a variable amount;
Programming Angle: A variable is a memory used to store some/some of the values. We can think of variables as a box, boxes for storing items, items that can be clothes, toys, fruits ... such as

Express your thoughts (expressions)
Expressions are similar to the definitions in mathematics, expressions are algebraic expressions that have certain values, and use operators to concatenate constants and variables together. An expression can contain constants or variables.

string expression : "I" + "Love" + "You" + mychar//write the string expression, the value is a string.

numeric expression : num + 5*32 + 2.5//write numeric expression, value is numeric.

Boolean expression : 2>3 num==5 num<60//write Boolean-True or flase expression

Xiao Ming has 10 yuan, bought a book, spent 5 yuan, Little Red said: "Your remaining money plus my 6 yuan, you can buy a pencil-box."

1 <script type= "Text/javascript" >2     var num1 = 10-5;   Calculate how much money the remaining 3     var num2 = num1+6;   Little safflower How much money buy pencil box 4     document.write ("Xiao Ming still left:" +num1+ "Yuan" + "<br>"); 5     document.write ("Small safflower:" +num2+ "Yuan buy a pencil-box"); 6 </script>

+ number operator
An operator is a symbol used to specify a certain action in JavaScript.
(1) operator
Sun = numa + numb;
where "=" and "+" are both operators.
Arithmetic operators (+ 、-、 *,/, etc.)
Comparison operators (<, >, >=, <=, etc.)
logical operators (&&, | |,!) )。
Note: the "=" operator is an assignment, not equal to.
(2) "+" operator
In JavaScript,"+" is not just a representation of addition, it can also connect two strings.

mystring = "Java" + "Script"; // mystring The value "JavaScript" This string

Since add one, subtract one (+ + and--)
In addition to the arithmetic operator (+ 、-、 *,/), there are two very commonly used operators, from adding one "+ +" to one "--". Let's start with an example:

Mynum = ten;The value ofmynum//mynum becomes one-to-one//mynum value is changed back to ten

In the above example, mynum++ the Mynum value on the original basis to increase the 1,mynum--so that mynum on the original basis minus 1, in fact, can also be written as:

1 mynum = mynum + 1; // equivalent to mynum++ 2 mynum = mynum-1; // equivalent to mynum--

comparison operator
We first to do math problems, math test scores, Xiao Ming scored 90 points, Xiao Red Test 95 points, ask who test scores high?
A: Because the "> 90", so the red test results high.
the greater than sign ">" is the comparison operator, the small red exam results and Xiao Ming exam results are the operand, and is two operands. The
means that two operands are compared by comparison operators, and get the value True (True) and False (false). Meaning of the
Operator:
< less than
> Greater than
<= less than or equal to
>= is greater than or equal to
= = equals
! = does not equal

 1  var  a = 5; //  Define a variable, assign a value of 5  2  var  B = 9; //  defines a B variable, assigned a value of 9  3  document.write (a<b); // a is less than the value of B? The result is true (true)  4  document.write (a>=b); // a is greater than or equal to the value of B? The result is False (false)  5  document.write (a!=b); // a is not equal to the value of B? The result is true (true)  6  document.write (a==b); // a equals B value? The result is False (false)  

Logic and operators
Mathematics "A>b", JavaScript also means "a>b", Mathematics, "B is greater than a a, less than C" is "a<b<c", JavaScript used in && expression.
B>a && b<c//"&&" is and means, reading "B is greater than a" and "B is less than C"
As we participate in the college entrance examination, before entering the examination room, must produce the admission certificate and the ID card, both indispensable, otherwise can not take the examination, said:

1 if (with admission ticket&& 2{3 for examination exam 4 }

"&&" is the logical AND operator, only "&&" both sides of the value are satisfied (and true), the entire expression value is true.
Logical AND Operator Values table:

A B A&&b
True (True) True (True) True (True)
True (True) False (False) False (False)
False (False) True (True) False (False)
False (False) False (False) False (False)


Note: If A is false, a && B is false and will not be executed in B; Conversely, if a is true, the value of a && B is determined by the value of B.

I or you can either (logical OR operator )
"||" Logical OR operator, equivalent to "or" in life, when any one of the two conditions satisfies, the result of "logical OR" is "true"
Logical OR Operator Values table:

A B a| | B
True (True) True (True) True (True)
True (True) False (False) True (True)
False (False) True (True) True (True)
False (False) False (False) False (False)


Note: If A is true, a | | B is true and will not be executed in B; Conversely, if a is false, it is determined by the value of B to determine a | | The value of B

1 <script type= "Text/javascript" >2     var  numa,numb,jq1; 3     Numa=50; 4     Numb=55; 5     jq1= numa>numb| | numa==numb; 6     document.write ("JQ1 value is:" +jq1+ "<br>")7 </script>

Topsy (logical non-operator)
"!" is the logical non-operator, that is, the meaning of "no", not true or false, not false is true.
Logical non-operator values table:

A ! A
True (True) False (False)
False (False) True (True)

Cases:

 1  var  a=3  2   3   C;  4  c=! (B>a); //  B>a value is true,! (B>a) value is False  5  c=! (B<a); //  
1 <script type= "Text/javascript" >2     var  numa,numb,jq1; 3     Numa=60; 4     Numb=70; 5     jq1=! (numa<numb); 6     document.write ("JQ1 value is:" +jq1+ "<br>")// Output value JQ1 value is: false7 </script>

Maintain sequencing (operator precedence)
Example one:

1 var numa=3; 2 var numb=63//  result is 0

Example two:

1 var numa=3; 2 var numb=63// result is -24.75

Precedence between Operators (high-to-low):
Arithmetic operator → comparison operator → logical operator → "=" assignment symbol
If the operation of the sibling is done in the left-to-right order, the multi-level brackets are outward .

 1  var  numa=3  2   3  jq= numa + >10 && numb * 3<2; //  
 1  <script type= "Text/javascript" >2  var   numa,numb,jq1;  3  numa=5;  4  numb=2;  5  Jq1=numa + >10 && numb * 3<20;
    6  jq2= ((NUMA + +)/(7-NUMB)) * 37  document.write (the value of "JQ1" is: "+jq1+" <br> "); // JQ1 is: true  8  document.write (the value of JQ2 is: "+JQ2); // JQ2 is: +  9  </script> 
1<script type= "Text/javascript" >2     vara,b,sum;3     varA = 5;4     varb = 100%7; 5sum = a > B && a*b > 0 ;6document.write ("I think the value of a is:" + 5 + "B is the value:" + 2 + "The value of sum is:" +true+ "<br/>");7document.write ("The answer is, after the first round of calculation, A is:" + A + "; B is:" +b + "; The first calculation sum is:" + sum + "<br/>");8 9sum = ((++a) + 3)/(2-(--b)) * 3; Tendocument.write ("After another calculation, I think the value of a is:" + 6 + "B is the value:" + 1 + "The value of sum is:" + + "<br/>");  Onedocument.write ("The answer is, after the second round of calculation, A is:" + A + "; B is:" + B + "; The second calculation sum is:" + sum + ", the type of sum is also changed.) "); A</script>

JavaScript Advanced--(JS Basic grammar) Notes collation

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.