-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathjavascript.chicken_eser
114 lines (109 loc) · 2.03 KB
/
javascript.chicken_eser
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
javascript
#===
var name = "Steven";
name; // Steven
#===
var name = "Steven";
if(name === "Steven"){
"What a nice mohawk";
}else{
"Your hair is alright, I guess";
}
// What a nice mohawk
#===
var person = {
name: "Steven"
};
person["name"] // Steven
person.name // Steven
#===
var person = {
name: "Steven",
profession: "Teacher"
};
person.likes = "Bourbon";
person.likes; // Bourbon
#===
function sayHello(){
return "Hello";
}
sayHello(); // Hello
#===
function sayHelloTo(person){
return "Hello, " + person;
}
sayHelloTo("Bob"); // Hello, Bob
#===
var bob = {
name: "Bob",
introduce: function(){
return "Oh Hai! I'm " + this.name;
}
};
bob.introduce(); // Oh Hai! I'm Bob
#===
function Person(name){
this.name = name;
}
var bob = new Person("Bob");
bob.name; // Bob
#===
function Person(name){
this.name = name;
}
Person.prototype.introduce = function(){
return "Oh Hai! I'm " + this.name;
}
var bob = new Person("Bob");
bob.introduce(); // Oh Hai! I'm Bob
#===
var outside = "I'm outside";
function whatIsOutside(){
return outside;
}
whatIsOutside(); // I'm outside;
#===
function youCanNotSeeMe(){
var secret = 42;
}
youCanNotSeeMe();
secret; // Error: secret is not defined.
#===
var canSee = true;
function performMagicTrick(){
canSee = false;
}
canSee; // true
performMagicTrick();
canSee; // false
#===
var theBoss = "My Wife";
function assertDominanceInMyHead(){
var theBoss = "Me!!"
}
theBoss; // My Wife
assertDominanceInMyHead();
theBoss; // My Wife
#===
(function(){
return "If a function is defined and never called, does it make a sound?"
}); // nothing happens
#===
(function(){
return "Right Away!"
})(); // Right Away!
#===
function add(first, second){
return first + second;
}
function calculate(number1, number2, calculationFunction){
return calculationFunction(number1, number2)
}
calculate(5, 5, add); // 10
#===
function calculate(number1, number2, calculationFunction){
return calculationFunction(number1, number2)
}
calculate(5, 5, function(first, second){
return first + second;
}); // 10