- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascriptBasics.js
More file actions
Latest commit
58 lines (50 loc) · 1.43 KB
/
Copy pathjavascriptBasics.js
File metadata and controls
58 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//**********************************************
//You should pick either declaration or expression functions. Only use 1 of these types in your code:
//FUNCTION DECLARATION
functionfoo(){
console.log(“functiondeclaration”);
}
//FUNCTION EXPRESSION - Assigns anonymous expression to a variable
varbar=function(){
console.log(“functionexpression”);
}
//(it is recommended that you start with expressions only)
//**********************************************
//ARGUMENTS VS PARAMTERS
//Here, input is an argument:
varbar=function(input){
console.log(input);
}
//Here, x is a variable:
varx=‘Helloworld!’;
bar(x);
//**********************************************
//Does order matter with parameters?
// YES - IT DOES MATTER
bar(1,2,3);
// is different than
bar(3,2,1);
//**********************************************
//SCOPE
//Think of a pyramid. This is known as a "call stack."
//Inner functions can see variables in outer functions.
functiona(){
varx=5;
functionb(){
vary=10;
functionc(){
varz=15;
}
functiond(){
console.log(x);//this equals 5
console.log(y);//this equals 10
console.log(z);//this is undefined
}
}
}
// In the above example, var z in function c is otuside of function d's scope.
//**********************************************
//METHOD VS FUNCTION
varobj={};
obj.foo=function(){};//method
varbar=function(){};//function