Variable

  1. Variable naming

    Variable names can be capitalized because JS is case-sensitive.


  2. Variable assignment

    = is an assignment symbol. The usage is to assign the value on the right side of the equal sign to the variable on the left side of the equal sign.

    var box can be unassigned first when declaring variables, but it must be assigned with =.


    1
    2
    3
    4
    var box = 1;
    var a = 5;
    var b = a = box;
    console.log(a, b, box) //result: 1, 1, 1.

  3. Data Types in JavaScript

    • Primitive data type: Number, String, Boolean, undefined, null. (Symbol in ES6)
    • Reference data types: Object, Array, Function.

    There is no need to declare a type when a variable is declared. It is okay to store different data types before and after the variable, for example, var b=123; var b="hello";.

    There is no floating point numbers in JS. Both integers and decimals are of type number.

    String type data must be added with "". The data added with "" must also be a string.

    The boolean type has only a=true; b=false; (true and false are keywords).

    Undefined is used for unassigned variables. The result of var a; console.log(a) is undefined. Undefined is used to automatically initialize variables.

    Null is a null object pointer.


  4. Operator

    Operator: Symbols that operate on data.

    Expressions: All expressions are connected by operators, and expressions and data are equivalent. (because the result of an expression must be data)

    Arithmetic operators: + - * / ++ -- %


  5. a++

    a++ self increment (+1 on the basis of itself, and then assign to itself).

    ++ When used alone, a++ and ++a are the same. When ++ is not used alone (eg b=a++), it is different before and after.

    ++a: +1 before participating in other operations.

    a++: first use the previous value to participate in the operation, and then increment 1 to itself after the operation is completed.


    1
    2
    3
    4
    var a = 10;
    var b = a++;
    console.log(a) //11
    console.log(b) //10

Share