-
Notifications
You must be signed in to change notification settings - Fork 1
/
lesson04.js
46 lines (36 loc) · 959 Bytes
/
lesson04.js
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
// Functions
'use strict';
function morningGreeting (name) {
return 'God morning to you ' + name;
}
console.log(morningGreeting('vicente'));
var a = function () {
return 'God morning to you me';
};
console.log(a);
console.log(a());
// iife
var a = (function (name) {
return 'God morning to you me ' + name;
}('vicente'));
console.log(a);
var test = 'this is public';
function testingScope () {
var test2 = 'this is private';
// test3 = 'this is public?'; // use 'use strict' to catch this errors
return test + ' ' + test2;
}
console.log(testingScope());
// This should fail, uncomment it to test it.
// console.log(test + ' ' + test3);
var initial = 'D';
function GetName (initial) {
var firstName = 'John';
return function () {
var lastName = 'Smith';
return 'My name is ' + firstName + ' ' + initial + '. ' + lastName;
};
}
var name = new GetName(initial);
console.log(name);
console.log(name());