Skip to content

frontendmaster

I started to enroll kyle's lesson. When I did GFE problem, I sometimes been confused about why, I hope I could think more and learn deeper in this. Even I know I can't do it in one time.

Equality

KP68DStest 6WLqywtest

==

  • allow coercion
  • toNumber()
    • compare as number
  • can't coercion(object with other types)
  • toPrimitive()

Corner case

  • [] == ![] //true

===

  • check type first
  • if NaN, -0, they are not equal
  • obj comparison
  • need to point to the same object/array

Static type

Know your type will improve your code quality. not just depend on typescript.

scope

  • target (assign value / declare) - runtime
  • source (get value) - compile time

named function Pros

  1. Reliable function self-reference (recursion, etc)
  2. More debuggable stack traces
  3. More self-documenting code
  4. arrow function is anonymous function

advanced scope

  • dynamic scope
  • depends on where the function is called
  • lexical scope
  • depends on where the function is declared

block scope

  • to solve name collision
  • encapsulation
  • use let, const (caused var will hoisting) to block scope
  • use in condition or loop
  • var can be reused in the same scope, but let, const can't
  • store temporary value into block scope

const

  • can't be reassigned
  • can't be redeclared
  • must be assigned when declare
  • use with immutable primitive values(less confusion)

hoisting

  • function execution first, then definition

Closure