mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-14 07:00:51 -04:00
refactor(curriculum): JS comparisons quiz (#58408)
Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
@@ -7,7 +7,7 @@ dashedName: quiz-javascript-comparisons-and-conditionals
|
||||
|
||||
# --description--
|
||||
|
||||
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
|
||||
To pass the quiz, you must correctly answer at least 9 of the 10 questions below.
|
||||
|
||||
# --quizzes--
|
||||
|
||||
@@ -17,33 +17,7 @@ To pass the quiz, you must correctly answer at least 18 of the 20 questions belo
|
||||
|
||||
#### --text--
|
||||
|
||||
What's the difference between `==` and `===`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
There is no difference, both have the exact same function.
|
||||
|
||||
---
|
||||
|
||||
`==` checks both values and its data type, while `===` only checks for value.
|
||||
|
||||
---
|
||||
|
||||
Both operators check the data type of the value, but only `===` compares values deeply.
|
||||
|
||||
#### --answer--
|
||||
|
||||
`===` compares the value and type without type coercion, while `==` attempts to convert them to the same type before comparing.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
console.log(5 === "5");
|
||||
```
|
||||
|
||||
What's the output of the code above?
|
||||
What's the result of the expression `undefined > 0`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
@@ -51,11 +25,11 @@ What's the output of the code above?
|
||||
|
||||
---
|
||||
|
||||
`NaN`
|
||||
`undefined`
|
||||
|
||||
---
|
||||
|
||||
An error is raised.
|
||||
`null`
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -65,28 +39,6 @@ An error is raised.
|
||||
|
||||
#### --text--
|
||||
|
||||
Which of the following is NOT a comparison operator?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`===`
|
||||
|
||||
---
|
||||
|
||||
`!==`
|
||||
|
||||
---
|
||||
|
||||
`<=`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`?==`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which logical operation does `||` represent?
|
||||
|
||||
#### --distractors--
|
||||
@@ -109,12 +61,12 @@ OR
|
||||
|
||||
#### --text--
|
||||
|
||||
What's the output of the following code?
|
||||
|
||||
```js
|
||||
console.log(5 === 2 + 3 || 4 == 2);
|
||||
```
|
||||
|
||||
What's the output of the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`undefined`
|
||||
@@ -139,15 +91,15 @@ What is a truthy and falsy value?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Value that's both `true` and `false`.
|
||||
A value that's both `true` and `false`.
|
||||
|
||||
---
|
||||
|
||||
Value that changes depending on context.
|
||||
A value that changes depending on context.
|
||||
|
||||
---
|
||||
|
||||
Value that functions differently than `true` or `false` value.
|
||||
A value that functions differently than `true` or `false` value.
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -157,14 +109,14 @@ A value that is considered `true` or `false` when encountered in a Boolean conte
|
||||
|
||||
#### --text--
|
||||
|
||||
What's logged to the console from the code below?
|
||||
|
||||
```js
|
||||
if (1) {
|
||||
console.log("True!");
|
||||
}
|
||||
```
|
||||
|
||||
What's printed to the console from the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`false`
|
||||
@@ -179,29 +131,7 @@ An error is raised.
|
||||
|
||||
#### --answer--
|
||||
|
||||
`"True!"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which of the following is NOT a truthy value?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`"false"`
|
||||
|
||||
---
|
||||
|
||||
`13`
|
||||
|
||||
---
|
||||
|
||||
`-1`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`0`
|
||||
`True!`
|
||||
|
||||
### --question--
|
||||
|
||||
@@ -211,11 +141,11 @@ What's the difference between `undefined` and `null`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
No difference.
|
||||
`null` and `undefined` point to an out-of-range memory location and are inaccessible.
|
||||
|
||||
---
|
||||
|
||||
`null` is the implicit value assigned to variables.
|
||||
`null` is the implicit value assigned to variables and it can not be changed, while `undefined` is the explicit value assigned to variables.
|
||||
|
||||
---
|
||||
|
||||
@@ -223,146 +153,35 @@ No difference.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Variables not assigned a value has the value `undefined`, while `null` is used to represent the intentional absence of any object value.
|
||||
Variables without a value are `undefined`, while `null` represents an intentional absence of an object value.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
const a = Boolean(undefined);
|
||||
```
|
||||
|
||||
The value of `a` in the code above is...
|
||||
What happens when you don't include `break` while implementing a `switch` statement?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`undefined`
|
||||
The `switch` statement will stop abruptly.
|
||||
|
||||
---
|
||||
|
||||
`true`
|
||||
The `switch` statement will throw an error after previous statement.
|
||||
|
||||
---
|
||||
|
||||
`NaN`
|
||||
The `switch` statement will exit after the first match.
|
||||
|
||||
#### --answer--
|
||||
|
||||
`false`
|
||||
The code continues to evaluate the following `case` statements, even after finding a match.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
if (2 == 2) {
|
||||
console.log("A");
|
||||
} else {
|
||||
console.log("B");
|
||||
}
|
||||
```
|
||||
|
||||
What's printed to the console when the code above executes?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
An error is raised.
|
||||
|
||||
---
|
||||
|
||||
`"B"`
|
||||
|
||||
---
|
||||
|
||||
Nothing gets printed to the console.
|
||||
|
||||
#### --answer--
|
||||
|
||||
`"A"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
if (2 == "2") {
|
||||
// Statement.
|
||||
}
|
||||
```
|
||||
|
||||
What will happen when the code is ran?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
The statement will output a warning and exits the program.
|
||||
|
||||
---
|
||||
|
||||
The statement will not run.
|
||||
|
||||
---
|
||||
|
||||
The statement will throw an error.
|
||||
|
||||
#### --answer--
|
||||
|
||||
The statement will run.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
if (2 == "2") {
|
||||
const a = 2;
|
||||
}
|
||||
console.log(a);
|
||||
```
|
||||
|
||||
What is printed to the console with code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`2`
|
||||
|
||||
---
|
||||
|
||||
Nothing gets printed.
|
||||
|
||||
---
|
||||
|
||||
`undefined`
|
||||
|
||||
#### --answer--
|
||||
|
||||
An error is raised.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What happens when you don't include `break` while implementing a switch statement?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
The switch statement will stop abruptly.
|
||||
|
||||
---
|
||||
|
||||
The switch statement will throw an error after previous statement.
|
||||
|
||||
---
|
||||
|
||||
The switch statement will exit after the first match.
|
||||
|
||||
#### --answer--
|
||||
|
||||
The code continues to evaluate the following case statements, even after finding a match.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
What is printed to the console from the code below?
|
||||
|
||||
```js
|
||||
const a = 2;
|
||||
@@ -373,8 +192,6 @@ if (1 == "1") {
|
||||
console.log(b);
|
||||
```
|
||||
|
||||
What will be printed to the console from the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
An error is raised.
|
||||
@@ -401,49 +218,57 @@ undefined
|
||||
|
||||
#### --text--
|
||||
|
||||
What keyword is used in a switch statement to handle cases when all of the specified cases are false?
|
||||
What will be the output of the following JavaScript code?
|
||||
|
||||
```js
|
||||
let vehicle = "car";
|
||||
|
||||
switch (vehicle) {
|
||||
case "bike":
|
||||
console.log("Bikes are two-wheelers.");
|
||||
break;
|
||||
case "car":
|
||||
console.log("Some cars are 4x4.");
|
||||
case "truck":
|
||||
console.log("Trucks can carry heavy loads.");
|
||||
break;
|
||||
default:
|
||||
console.log("Unknown vehicle.");
|
||||
}
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`then`
|
||||
```md
|
||||
Some cars are 4x4.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
`after`
|
||||
```md
|
||||
Some cars are 4x4.
|
||||
Trucks can carry heavy loads.
|
||||
Unknown vehicle.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
`else`
|
||||
```md
|
||||
Unknown vehicle.
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
`default`
|
||||
```md
|
||||
Some cars are 4x4.
|
||||
Trucks can carry heavy loads.
|
||||
```
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What does the operator `&&` represent?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
XOR
|
||||
|
||||
---
|
||||
|
||||
OR
|
||||
|
||||
---
|
||||
|
||||
NOT
|
||||
|
||||
#### --answer--
|
||||
|
||||
AND
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
What is printed to the console with code below?
|
||||
|
||||
```js
|
||||
let x = 5;
|
||||
@@ -454,8 +279,6 @@ if (x > 1 && x < 10) {
|
||||
}
|
||||
```
|
||||
|
||||
What is printed to the console with code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
An error is raised.
|
||||
@@ -466,57 +289,9 @@ Nothing is printed.
|
||||
|
||||
---
|
||||
|
||||
`"x is not between 1 and 10"`
|
||||
`x is not between 1 and 10`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`"x is between 1 and 10"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What does the operator `!` do?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It will reverse the value of a variable.
|
||||
|
||||
---
|
||||
|
||||
It will do "AND" operation.
|
||||
|
||||
---
|
||||
|
||||
It will do "OR" operation.
|
||||
|
||||
#### --answer--
|
||||
|
||||
It will negate the boolean value or converts a non-boolean expression to its opposite.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
```js
|
||||
console.log(!!true);
|
||||
```
|
||||
|
||||
What is printed to the console with the above code?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`false`
|
||||
|
||||
---
|
||||
|
||||
It raises an error, you can't double negate an expression.
|
||||
|
||||
---
|
||||
|
||||
`undefined`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`true`
|
||||
`x is between 1 and 10`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user