DEV Community


Posted on

My Raw Notes for the Week of 9-27-2021

In Simpson's thinking, there are three "pillars" of JS:
1) Types/Coercion
    - Primitive Types
        - undefined
        - string
        - number
        - boolean
        - object
            - function
            - array
        - symbol (not used much)
        - null (sort of)
    - Converting Types
        - Number and String:
            - Number + Number = Number <this is the only one of the four in which the '+' means 'mathematical addition' (as opposed to 'concatenation')>
            - Number + String = String
            - String + Number = String
            - String + String = String
        - Truthy and Falsy
            - If we were to coerce a non-boolean value into a boolean, would it be true or false? If true, the value is Truthy. If false, Falsy
            - Falsy values in JS: '', 0, -0, null, NaN, false, undefined. Truthy values in JS: everything else
    - Checking Equality
        - '==' allows coercion (types different)
        - '===' disallows coercion (types same)
2) Scope/Closures
    - FYI:
        - Simpson: Scope is where the JS engine looks for things
    - FYI:
        - Example of what's called a 'function statement' or 'function declaration': function funcDec() {}
        - Example of what's called an 'anonymous function expression': const anonFuncExp = function() {}
        - Example of what's called a 'named function expression': const namedFuncExp = function namedFuncExp() {}
    - Nested Scope
    - Closure
        - Simpson's definition: "Closure is when a function "remembers" the variables [created] outside of it, even if you pass [or call] that function elsewhere."
3) this/Prototypes
    - this
        - Simpson: "A function's 'this' references the execution context for that call, determined entirely by HOW THE FUNCTION WAS CALLED."
    - Prototypes
        - Function constructors and their interaction with 'this'
    - Class{}
        - using the 'class' keyword as an improved syntax for setting up a Function constructor

Whether a variable is declared but not assigned a value or it's simply never declared, it has a type of 'undefined'.

For 'let v = null', 'typeof v' is 'object'. This is a bug in the JS language which can't be changed now.
For 'v = function(){}', 'typeof v' is 'function'. This is strange because 'function' is a subtype of 'object', but it's not a mistake and it is useful.
For 'let v = [1, 2, 3]', 'typeof v' is 'object'. This makes sense because 'function' is a subtype of 'object'.
Enter fullscreen mode Exit fullscreen mode

Discussion (0)