03 JavaScript Basis

1. Variables and Data Types

  • Number: Floating point numbers, for decimals and integers
  • String: Sequence of characters, used for text
  • Boolean: Logical data type that can only be true or false
  • Undefined: Data type of a variable that does not have a value yet
  • Null: Also means 'non- existent'

    2. Variables Mutation and Type Coercion

    var firstName = 'john';
    var age = 28;
    
    console.log(firstName+age);
    
    var job, isMarried;
    
    job = 'teacher';
    
    isMarried = false;
    
    console.log(job+isMarried);
    
    var lastName = prompt('what is his last name?');
    
    console.log(lastName);
    

    3. Basic Operators

    var year, yearJohn ,yearMark;
    year = 2018;
    ageJohn = 28;
    ageMark = 33;
    
    //Math Operators
    year = 2018;
    yearJohn = year - ageJohn;
    yearMark = year - ageMark;
    console.log(yearJohn, yearMark);
    
    //Logical Operators
    var johnOlder = ageJohn > ageMark;
    console.log(johnOlder);
    
    //Typeof Operators
    console.log(typeof johnOlder);
    console.log(typeof ageJohn);
    console.log(typeof x);
    

    4. Operator Precedence

    Precedence Operator type Associativity Individual operators
    20 Grouping n/a ( … )
    19 Member Access left-to-right … . …
    Computed Member Access left-to-right … [ … ]
    new (with argument list) n/a new … ( … )
    Function Call left-to-right … ( )
    Optional chaining left-to-right ?.
    18 new (without argument list) right-to-left new …
    17 Postfix Increment n/a … ++
    Postfix Decrement … --
    16 Logical NOT right-to-left ! …
    Bitwise NOT ~ …
    Unary Plus + …
    Unary Negation - …
    Prefix Increment ++ …
    Prefix Decrement -- …
    typeof typeof …
    void void …
    delete delete …
    await await …
    15 Exponentiation right-to-left … ** …
    14 Multiplication left-to-right … * …
    Division … / …
    Remainder … % …
    13 Addition left-to-right … + …
    Subtraction … - …
    12 Bitwise Left Shift left-to-right … << …
    Bitwise Right Shift … >> …
    Bitwise Unsigned Right Shift … >>> …
    11 Less Than left-to-right … < …
    Less Than Or Equal … <= …
    Greater Than … > …
    Greater Than Or Equal … >= …
    in … in …
    instanceof … instanceof …
    10 Equality left-to-right … == …
    Inequality … != …
    Strict Equality … === …
    Strict Inequality … !== …
    9 Bitwise AND left-to-right … & …
    8 Bitwise XOR left-to-right … ^ …
    7 Bitwise OR left-to-right … | …
    6 Logical AND left-to-right … && …
    5 Logical OR left-to-right … || …
    4 Conditional right-to-left … ? … : …
    3 Assignment right-to-left … = …
    … += …
    … -= …
    … **= …
    … *= …
    … /= …
    … %= …
    … <<= …
    … >>= …
    … >>>= …
    … &= …
    … ^= …
    … |= …
    2 yield right-to-left yield …
    yield* yield* …
    1 Comma / Sequence left-to-right … , …

    5. Falsy and Truthy values

    Falsy values:
    • undefined
    • null
    • 0
    • ''
    • ""
    • NaN
    Truthy values:
    • not falsy values

    • 6. Equality Operators

    • ==
    •        "==" does type coercoion (it converts the string to a number)

    • === (more strict)
    •        "==="does NOT coercoion

    猜你喜欢

    转载自blog.csdn.net/flavioy/article/details/100420884