Skip to content

Commit 2068366

Browse files
feat: more questions var const scope
1 parent 85f37f2 commit 2068366

File tree

15 files changed

+140
-7
lines changed

15 files changed

+140
-7
lines changed

.eslintrc.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"react/jsx-curly-brace-presence": "off",
3333
"no-unused-expressions": 0,
3434
"chai-friendly/no-unused-expressions": "off",
35-
"eqeqeq": "off"
35+
"eqeqeq": "off",
36+
"no-var": 0,
37+
"vars-on-top": "off",
38+
"no-plusplus": "off",
39+
"block-scoped-var": "off",
40+
"no-use-before-define": "off"
3641
}
3742
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// What will console.log from the following code;
1+
// What will console.log from the following code:
22

33
console.log(Boolean(null), Boolean(' '), Boolean('0'), Boolean('false'));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// What will console.log from the following code;
1+
// What will console.log from the following code:
22

33
console.log('B' < 'b', '01' == 1, false == '0', '' == 0);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Const Keyword Continued",
3+
"key": "const-keyword-continued",
4+
"description": "Const keyword assigned an object",
5+
"difficulty": 2,
6+
"explanation": "const keyword is used to declare a constant. Objects are not immutable though, the value of the const hasn't change because the object was mutated, the constant still points to the same object.",
7+
"correctAnswer": "'world'",
8+
"answers": [
9+
{
10+
"answer": "Uncaught ReferenceError: foo is not defined"
11+
},
12+
{
13+
"answer": "'hello'"
14+
},
15+
{
16+
"answer": "'world'"
17+
},
18+
{
19+
"answer": "Uncaught TypeError: Assignment to constant variable."
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// What will console.log from the following code:
2+
3+
const foo = { bar: 'hello' };
4+
foo.bar = 'world';
5+
console.log(foo.bar);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Const Keyword",
3+
"key": "const-keyword",
4+
"description": "Const Keyword",
5+
"difficulty": 2,
6+
"explanation": "const keyword is used to declare a constant, it can't be initiated without a value. It can't be reassigned a different value.",
7+
"correctAnswer": "Uncaught TypeError: Assignment to constant variable.",
8+
"answers": [
9+
{
10+
"answer": "Uncaught ReferenceError: foo is not defined"
11+
},
12+
{
13+
"answer": "5"
14+
},
15+
{
16+
"answer": "'hello'"
17+
},
18+
{
19+
"answer": "Uncaught TypeError: Assignment to constant variable."
20+
}
21+
]
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// What will console.log from the following code:
2+
3+
const foo = 5;
4+
foo = 'hello'; // eslint-disable-line
5+
console.log(foo);

data/javascript/index.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
{
2525
"title": "Comparison Operator",
2626
"key": "comparison-operator"
27+
},
28+
{
29+
"title": "Let Variable",
30+
"key": "let-variable"
31+
},
32+
{
33+
"title": "Const Keyword",
34+
"key": "const-keyword"
35+
},
36+
{
37+
"title": "Const Keyword Continued",
38+
"key": "const-keyword-continued"
39+
},
40+
{
41+
"title": "Scope Var",
42+
"key": "scope-var"
2743
}
2844
]
2945
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Let Variable",
3+
"key": "let-variable",
4+
"description": "Let Variable",
5+
"difficulty": 1,
6+
"explanation": "let keyword is used to declare a variable, it is initiated with a value of undefined. it allows you to change the value of the variable.",
7+
"correctAnswer": "undefined 'fuzz'",
8+
"answers": [
9+
{
10+
"answer": "Uncaught ReferenceError: foo is not defined"
11+
},
12+
{
13+
"answer": "undefined 'fuzz'"
14+
},
15+
{
16+
"answer": "undefined 6"
17+
},
18+
{
19+
"answer": "null 'fuzz'"
20+
}
21+
]
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// What will console.log from the following code;
2+
3+
let foo;
4+
let bar = 6;
5+
bar = 'fuzz';
6+
console.log(foo, bar);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// What will console.log from the following code;
1+
// What will console.log from the following code:
22

33
console.log(true - false, 2 - 'foo', '3' - 1);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// What will console.log from the following code;
1+
// What will console.log from the following code:
22

33
console.log(Number('5'), Number('undefined'), typeof Number('foo'));

data/javascript/scope-var/index.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"title": "Scope Var",
3+
"key": "scope-var",
4+
"description": "Understand the var keyword scoping",
5+
"difficulty": 3,
6+
"explanation": "var is scoped to functions but is not block scoped, like in a for loop.",
7+
"correctAnswer": "5 4 undefined",
8+
"answers": [
9+
{
10+
"answer": "undefined 4 undefined"
11+
},
12+
{
13+
"answer": "5 4 undefined"
14+
},
15+
{
16+
"answer": "Uncaught ReferenceError: baz is not defined"
17+
},
18+
{
19+
"answer": "4 4 undefined"
20+
}
21+
]
22+
}

data/javascript/scope-var/question.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// What will console.log from the following code;
2+
3+
var bar;
4+
for (var foo = 0; foo < 5; foo++) {
5+
bar = foo;
6+
}
7+
console.log(foo, bar, baz);
8+
var baz = 10;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// What will console.log from the following code;
2-
const simpleAdd = (a, b) => a + b;
1+
// What will console.log from the following code:
32

3+
const simpleAdd = (a, b) => a + b;
44
console.log(simpleAdd(2, 3));

0 commit comments

Comments
 (0)