- Be able to read jQuery source code and able to under stand what is happening.
- Complete and understand of writing our own library.
Syntax Parser a program that reads your code and determines what it does and if its grammar/syntax is valid.
When you write JavaScript it isn't directly telling computer what to do. You're writing code, but then someone else built programs that convert your JS into something that computer can understand. Those programs are called compilers or interpreters.
Compilers go character by character and translate your code into a set of instructions. Important to understand is that during that process programmers who wrote that compiler can choose to do extra stuff. Your code is not what actually is given to a computer but a translation of it.
Lexical environment - where something sits physically in the code you write and what surrounds it. In JavaScript where you write something is important.
example for lexical environment can be -
- inside function
- outside function
Execution context - a wrapper to help manage the code that is running. There are lots of lexical environments, areas of the code that you look at physically, but which one is currently running is managed via execution contexts. Execution context contains your running code, but it can also contain things beyond what you've written in your code. Because remember that your code is being translated by a syntax parser.
Name value pair - a name which maps to a unique value. The name may be defined more than once, but can only have one value in any given execution context.
Object - is a collection of name value pairs.
Global execution context - the base execution context. It creates global object and special variable called this
. In a browser this
global object is window
.
NOTE: In javascript Global means not inside a function
Hoisting - because of the way JS works, you can write in your code a call to a function before an actual function and it will execute without any errors.
b();
function b() {
console.log('This works!');
}
When parser runs through code it recognizes where you created variables and functions and it sets up memory space for them. So before your code begins to be executed, JS engine has already set aside memory space for all the variables and functions you created. When the code begins to execute line by line it can access it.
However, for variables JS engine puts a placeholder undefined
, because it doesn't know what it's value will ultimately end up being until it starts executing that line of code.
console.log(a);
var a = 'Hello World!';
- CREATION PHASE
- EXECUTION PHASE
undefined
- is a special value, a keyword that JavaScript sets up to all variables during a creation phase of execution context.
undefined
in javascript means that the value of the variable in never set/initialized.
In the execution phase JS engine runs your code line by line.
Single threaded - JavaScript is a single threaded, synchronous language. That means one command execution at a time. Maybe not under the hood of the browser but from our perspective as programmers it is single threaded.
Synchronous execution - means one at a time and in order that it appears.
Invocation - running or calling a function by using parenthesis ().
Execution Stack - every time you invoke a function a new execution context is created for that function and is put on top of execution stack.