Design Portfolio


JavaScript: Understanding the Weird Parts (Part 2)

Types and JavaScript

  • dynamic typing - you do not specify the data type of the variable to the JavaScript engine; it figures it out while the code is running
  • variables can hold different types of values because the types are determined during execution
  • static typing - specify what data type you intend to hold inside a variable

Primitive Types

  • six primitive types in JavaScript
  • primitive type - data type that represents a single value, aka not an object

    • an object is a collection of name/value pairs
  • undefined - represents a lack of existence. Do not set variables to undefined.

  • null - also represents a lack of existence. Use when you want to say something doesn't exist. Can set variables to null.
  • boolean - true or false
  • number - floating point number, essentially there is always a decimal attached to it. JavaScript only has one numeric type.
  • string - a sequence of characters, both ' and " can be used
  • symbol - new, used in ES6


  • operator - a special function that is syntactically (written) differently; generally takes two parameters and returns one result
    • infix notation: 3 + 4
    • prefix notation: + 3 4
    • postfix notation: 3 4 +
  • an operator is essentially a function call passing two parameters and returning a value

Operator Precedence and Associativity

  • operator precedence - which operator gets called first if there's more than one on the same line of executable code
  • associativity - what order operator functions get called in: left-to-right or right-to-left when functions have the same precedence
    • higher precedence gets called first, ex: multiplication before addition
var a = 3 + 4 *5;
         // 3 + 20;
         // 23;
var a = 2, b = 3, c =4;
  a = b = c; // same associativity
console.log(a); //4
console.log(b); //4
console.log(c); //4

='s associativity is right-to-left, so a = b sets b to c then a to b.

  • grouping with parens () - anything in the () gets executed first since grouping has the highest possible precedence (19).