Javascript | Javascript kata |Node JS | Data Types | Variables | Control Flow | Scope and Environment | Objects | Functions | Events | Prototypal Inheritance | Three.js | 3DE Code Editor |

Javascript Data Types

There are 8 fundamental data types: Variables don't have types. The values have types. remember to use typeof operator.
  1. Numbers

  2. 5
    0b101
    0o5
    0x5
    5e7
    
    10 * "string" => NaN
    10/0 => Infinity
    -10/0 => -Infinity
    
    all numbers stored as 64bit floating point. never compare decimal numbers.
  3. Strings
  4. Can be defined with "" '' ``
    let s = "Jane is good"
    s.length //12
    s.toLowerCase()
    s.toUpperCase()
    
  5. Booleans

  6. true
    false
    
    Falsey Values
    ""
    0
    NaN
    0n  // Bigint value
    null
    undefined
    false
    
  7. Objects

  8. let person ={
     name: "Jane",  // don't forget the commas!
     age: 5
    }
    person.name;
    person["name"];
    person.age = 6;
    
    let newPerson = person;
    
    newPerson.age = 7;
    person.age;        // 7
    
    Note that newPerson points to the same Object as person
    let name = "Jane";
    let age = 8;
    let oldPerson = {
      name,
      age,
     }
    
    let somePerson = null;
    typeof somePerson; // 'object'
    
    This is a short cut.

    Arrays

    let a = [0, 1];  // undefined
    a.length;
    a[0] = 2;
    a.push(3);
    a.pop();
    a.unshift(4)
    a.shift().
    a.indexOf(1);
    
    map filter sort
    
  9. Functions

  10.  function add(x, y){
        return x+y;
     }
    
    let add1 = function(x, y){
        return x+y;
     }
    
    let add2 = (x, y) => {
        return x+y;
     }
    
  11. Undefined

  12. typeof blah; //undefined
    let x; //undefined
    blah.x //undefined
    blah[0] //undefined
    
    typeof undefined; // undefined
    typeof null; // object
    
  13. Bigints

  14. add a single lowercase n at end of number: 10n
      10n + BigInt(2) // 12n
    
  15. Symbols

  16. No two symbols are ever equal.
      let mySym = Symbol("aGoodSymbol");
    
      mySym;                             // Symbol(aGoodSymbol)
    
      let mySym1 = Symbol.for("aVeryGoodSymbol");
    

http:///wiki/?jsdatatypes

11apr23   admin