forked from spanic/JavaScriptBeginnerCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
105 lines (65 loc) · 2.17 KB
/
Copy pathscript.js
File metadata and controls
105 lines (65 loc) · 2.17 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
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
'use strict';
// By link or by value?
// ------------------------
var alpha, beta = "gamma";
alpha = beta;
alpha += "_updated";
console.log("Alpha: " + alpha + ", Beta = " + beta);
// ------------------------
// var, let and const usage
// ------------------------
console.log("Before declaration \"foo\" = " + foo);
var foo = 0;
if (true) {
var foo = 5;
}
console.log("Outside of the \"if\" clause \"foo\" eq. to " + foo);
// console.log(bar);
function test_function() {
var bar = "1703";
}
for (var i = 1; i < 11; i++) {
console.log("Iteration #" + i);
}
console.log("Outside of the loop \"i\" eq. to " + i);
// ------------------------
// Various functions arity
// ------------------------
var variableToChange = 500;
test_arguments(variableToChange, 600, 700);
console.log(variableToChange);
function test_arguments(InputParameter) {
console.log("Parameter: " + InputParameter);
console.dir(arguments);
for (let i = 1; i < arguments.length; i++) {
InputParameter = arguments[i];
console.log("Iteration #" + i + ", InputParameter = " + InputParameter +
", variableToChange = " + variableToChange);
}
variableToChange = InputParameter;
}
// ------------------------
// Types
// ------------------------
var firstNumber = 6, secondNumber = 14.997;
console.log(/*typeof (*/secondNumber / 0/*)*/); // Infinity
console.log(/*typeof (*/"A" * firstNumber/*)*/); // NaN
var emptyVariable = null;
console.log(/*typeof (*/emptyVariable/*)*/); // design error
// ------------------------
// Array disorientation
// ------------------------
let testArray = [1, 2, "OK", {"foo" : "bar"}];
// testArray.length += 100;
// testArray.push("New element");
console.dir(testArray);
// ------------------------
// Comparison chaos
// ------------------------
console.log('' == false);
console.log("\"null\" == 0? --> " + (null == 0) + ", \"null\" > 0? --> " + (null > 0) +
", \"null\" >= 0? --> " + (null >= 0)); // works like "false" OR "false" = "true"
console.log("\"undefined\" equals \"null\"? --> " + (undefined == null) +
", \"null\" >= 0 --> " + (null >= 0) + ", \"undefined\" >= 0? --> " + (undefined >= 0));
// transitivity? no, never heard.
// ------------------------