mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-03-02 02:01:39 -05:00
feat(curriculum): javascript comparisons quiz (#56633)
This commit is contained in:
@@ -17,439 +17,506 @@ Answer all of the questions below correctly to pass the quiz.
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What's the difference between `==` and `===`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
There is no difference, both have the exact same function.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`==` checks both values and its data type, while `===` only checks for value.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Both operators check the data type of the value, but only `===` compares values deeply.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`===` compares the value and type without type coercion, while `==` attempts to convert them to the same type before comparing.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
console.log(5 === "5");
|
||||
```
|
||||
|
||||
What's the output of the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`true`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`NaN`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
An error is raised.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`false`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is NOT a comparison operator?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`===`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`!==`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`<=`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`?==`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which logical operation does `||` represent?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
XOR
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
AND
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
NOT
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
OR
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
console.log(5 === 2 + 3 || 4 == 2);
|
||||
```
|
||||
|
||||
What's the output of the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`undefined`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`false`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
An error is raised.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`true`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What is a truthy and falsy value?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
Value that's both `true` and `false`.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Value that changes depending on context.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Value that functions differently than `true` or `false` value.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
A value that is considered `true` or `false` when encountered in a Boolean context.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
if (1) {
|
||||
console.log("True!");
|
||||
}
|
||||
```
|
||||
|
||||
What's printed to the console from the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`false`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Nothing gets printed to the console.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
An error is raised.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`"True!"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
Which of the following is NOT a truthy value?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`"false"`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`13`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`-1`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`0`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What's the difference between `undefined` and `null`?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
No difference.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`null` is the implicit value assigned to variables.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`null` is a global property, `undefined` is not.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
Variables not assigned a value has the value `undefined`, while `null` is used to represent the intentional absence of any object value.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
const a = Boolean(undefined);
|
||||
```
|
||||
|
||||
The value of `a` in the code above is...
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`undefined`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`true`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`NaN`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`false`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
if (2 == 2) {
|
||||
console.log("A");
|
||||
} else {
|
||||
console.log("B");
|
||||
}
|
||||
```
|
||||
|
||||
What's printed to the console when the code above executes?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
An error is raised.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`"B"`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
Nothing gets printed to the console.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`"A"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
if (2 == "2") {
|
||||
// Statement
|
||||
}
|
||||
```
|
||||
|
||||
What will happen when the code is ran?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
The statement will output a warning and exits the program.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
The statement will not run.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
The statement will throw an error.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
The statement will run.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
if (2 == "2") {
|
||||
const a = 2;
|
||||
}
|
||||
console.log(a);
|
||||
```
|
||||
|
||||
What is printed to the console with code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`2`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Nothing gets printed.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`undefined`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
An error is raised.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What happens when you don't include `break` while implementing a switch statement?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
The switch statement will stop abruptly.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
The switch statement will throw an error after previous statement.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
The switch statement will exit after the first match.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
The code continues to evaluate the following case statements, even after finding a match.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
const a = 2;
|
||||
if (1 == "1") {
|
||||
let b = 3;
|
||||
console.log(a + b);
|
||||
}
|
||||
console.log(b);
|
||||
```
|
||||
|
||||
What will be printed to the console from the code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
An error is raised.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
```js
|
||||
5
|
||||
3
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
```js
|
||||
5
|
||||
undefined
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`5`, and then an error is raised.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What keyword is used in a switch statement to handle cases when all of the specified cases are false?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`then`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
`after`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`else`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`default`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What does the operator `&&` represent?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
XOR
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
OR
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
NOT
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
AND
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
let x = 5;
|
||||
if (x > 1 && x < 10) {
|
||||
console.log("x is between 1 and 10");
|
||||
} else {
|
||||
console.log("x is not between 1 and 10");
|
||||
}
|
||||
```
|
||||
|
||||
What is printed to the console with code above?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
An error is raised.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
Nothing is printed.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`"x is not between 1 and 10"`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`"x is between 1 and 10"`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
What does the operator `!` do?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
It will reverse the value of a variable.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
It will do "AND" operation.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
It will do "OR" operation.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
It will negate the boolean value or converts a non-boolean expression to its opposite.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Placeholder question
|
||||
```js
|
||||
console.log(!!true);
|
||||
```
|
||||
|
||||
What is printed to the console with the above code?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Placeholder distractor 1
|
||||
`false`
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 2
|
||||
It raises an error, you can't double negate an expression.
|
||||
|
||||
---
|
||||
|
||||
Placeholder distractor 3
|
||||
`undefined`
|
||||
|
||||
#### --answer--
|
||||
|
||||
Placeholder answer
|
||||
`true`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user