Understanding the Weird Parts of JS Flashcards
syntax parser
a program that reads your code, determines what it does, and if its grammar (or syntax) is valid
compiler
interpretors for computers so the computer understands your code and converts it into instructions
it goes through code character by character
lexical environment
where something sits physically in the code you write
ie. a variable is on line 13 in the code
execution context
a wrapper to help manage the code that is running
object
a collection of name/value pairs
global execution context
- the base execution context
- creates 2 things in our code by the JS engine:
- a global object
- a special variable ‘this’
the window object
- the global object in browsers
- each window open in the browser has its own global object
- at the global level, the ‘this’ object is the same as the window object
global
- not inside a function
- code or variables not within a function
- when you create variables + functions not inside a function, they get attached to the global object
- there is no outer environment at the global level
ex:
in code:
const a = ‘Hello world!”;
in the console:
a // => ‘Hello world!’
window.a // => ‘Hello world!’
this.a // => ‘Hello world!’
execution context
table:
global object | ‘this’ | outer environment
_________________________________
your code!
hoisting
setup memory space for variables and functions
- a function in its entirety is saved in memory
- a var name is saved (not the case for let or const)
undefined
- a special value in JS
- the variable name exists, but the value has not been set, so JS sets the variable to the value ‘undefined’ and saves it to memory
Uncaught referenceError: [var name] is not defined
means that a variable has not been declared and saved to memory
single threaded synchronous execution
- single threaded: one at a time
- synchronous: one at a time in order
JS is executed line be line in the order of the code
execution stack
- whichever execution context that is on top of the stack is the one that is currently running
- every time a function is called, it’s put on top of the stack
- once the function finished executing, it is removed from the stack