JS --- basic grammar exercises: swap the values of two variables

    * JavaScript referred to as JS

    * JavaScript What is that?

    * Is a scripting language: does not need to compile, run directly
    * Is an interpreted language: encountered the same code is interpreted line of code
    * C # language is an object-oriented language, is also a compiled language, is used .net technology
    * Is a dynamically typed language --- not resolved
    * Is an object-based language --- not explain
    * Is a weakly typed language, variables when they are declared using the var
    * Strongly typed languages: C # is ----->
    * Stores a number: int num = 10; float num2 = 90.3;
 

    * JS divided into three parts:

    * 1. ECMAScript standard: basic syntax of js
    * 2. JUDGMENT
    * 3. GOOD
 

 * JS nearly 10 days with the invention

    

    * --- variable effect: operational data (stored data, the read data)

    * Variable declaration:
    * Var variable name;
    * There num;
    * Initialize variables
    * Var variable name = value; ----> literal way of assignment
    * Var str = "You Well";
 
    * Js the case is distinguishable
    * String js can use single quotes, double quotes can also be used temporarily recommend the use of double quotes ---
    * Js the end of each line of code to have a semicolon;
 

    * type of data:

    * Js the primitive data types: number, string, boolean, undefined, null, object
    * Null and undefined data is not much sense, null is the location of the object makes sense to speak ---
    * NaN ---- not a number, not a number and a digital calculation ---> The result is NaN
    * IsNaN () ---> determines the value of this variable is not or not a number is not a number --- if the result is true, false if the result is a number
    *
    * Number of data types ---- either integer or fractional number data types are
    ---- * string data type string, get the length of the string: variable name .length
    --- * boolean data type two values, true, false
    * Null ---- only one, null
    * Undefined ---- only one, undefined, a variable declaration, and no assignment
    * Object --- ----- Object Object Oriented time to explain
    *

    * Type conversion:

    * Other types of digital revolution
    * ParseInt () ----> to Integer
    * ParseFloat () ---> turn decimals
    Two strict * Number () ----> digital revolution than the above -----
    * Other types to String
    * .toString()
    * String();
    *
    * Other types of transfer boolean
    * Boolean () ----> is either true or false
    *

    * Operator: operator ----

    * Arithmetic operators: + - * /%
    * Composite Operators: + = - = = * / =% =
    * Assignment operator: = lowest priority
    * Unary operators: + -
    * Ternary operator:?:
    * Relational operators:> <> = <= = == === ==!!
    * Logical operators: && ||!
    *
    * Results relational operators are Boolean
    * Results logical operators are Boolean type
    *
    * Expression 1 && expression 2
    * If there is a false, the entire result is false
    * 2 expression expression 1 ||
    * Only a true, the overall result is true
    *! Expression --- the result is negated
    *

    * Exercise: swap the values ​​of two variables

1. The first variable exchange ideas: the use of third-party exchange temp

    // first variable exchange ideas: the use of third-party exchange temp 
    var num1 = 10; 
    var = 20 is num2; 
    value // num1 first taken out in the temp 
        temp = num1; 
    // then the value num2 num1 taken out on the 
        num1 num2 =; 
    // finally taken out on the value of temp num2 
        num2 = temp; 
        the console.log (num1, num2); 10 // 20 is

 

2. The second way exchange: generally applicable to digital

    The second exchange of //: generally applicable to digital 
    var num1 = 10; 
    var = 20 is num2; 
    // the value num1 num2 variable values and variables, adding taken out, re-assigned to num1 
        num1 = num1 + num2; // 30 
    // the variables values num1 and num2 variables taken out, the result of subtraction to reassign num2 
        num2 = num1 - num2; 30-20 = 10 // 
    // the value num1 and num2 variables the value of the variable is taken out, the result of subtraction to reassign num1 
        num1 = num1 - num2; // 30-10 = 20 is 
    the console.log (num1, num2) // 20 is 10

 

3. Third: expansion, variable exchange, Bitwise

    // Third: expansion, variable exchange, Bitwise 
    var num1 = 10; 
    var = 20 is num2; 
    num1 num2 ^ = num1; 
    num2 = ^ num1 num2; 
    num1 = num1 num2 ^; 
    the console.log (num1, num2); // 2010

 



Guess you like

Origin www.cnblogs.com/jane-panyiyun/p/11895706.html