This part is a summary of what i see some trivial basics of JS and its functions
- If we add script tag with codes in the HTML/php file, the js codes wont be cashed. For cashing, we need to link a external .js file.
- we can add two attribute to script tag “async” & “defer”.

Section-6 (Functions)
- We can invoke a function before declaration. It is explained by hoisting.
- In js, functions are first class value. Means we can assign a function to a variable. pass functions as argument and also return a function from inside another function.
- In 1st phase, js compiler goes top to bottom and takes all function and variable declaration and allocates memory for them and in 2nd phase and it starts execution.
alert(a); var a = 5; // compile phase: var a; //memory allocated but 5 is not assigned yet // then in execution phase it will again start execution from top. when it comes to line 1 it already knows that it has a variable named a but its value is not defined yet. so it will show 'undefined'
- For the both functions below, the “bar” will be local variable of the function. For creating local variable inside a function we have to use “var” keyword or use the variable as argument.
function foo(bar){ } function foo(){ var bar; }the following variable declaration will create a “num” variable in the global namespace.
function foo(){ bar = 5; } - returning function from functions:
var func = function(designation){ if(designation === "boss"){ return function(name){ alert("Hello Boss " + name); } }else return function(name){ alert("Hello " + name); } } var func2 = func(); func2("sajib");