curriculum/challenges/english/blocks/quiz-javascript-fundamentals/66edcd875b0d91de1fbbb492.md
To pass the quiz, you must correctly answer at least 18 of the 20 questions below.
Which one of these will create a String object?
String({ "Hello World" });
String("Hello World");
"Hello World".toString();
new String("Hello World");
How can you convert a String object into a string literal?
With the String() constructor.
With the .stringify() method.
Enclose the String object in double quotes.
With the .toString() method.
Why can you use methods like .length, .repeat(), .concat(), and .slice() on a string primitive in JavaScript?
Those methods exist natively on string primitives.
String primitives are stored as objects internally.
JavaScript temporarily converts the string primitive to an array.
JavaScript temporarily wraps the string primitive in a String object.
What will the following code log to the console?
let stringArray = [8, 9, 10].toString();
console.log(stringArray);
[8,9,10]
["8", "9", "10"]
"8", "9", "10"
"8,9,10"
Which of the following returns a Number object from the string "123"?
Object("123")
"123".toNumber()
Number("123")
new Number("123")
What will Number(true) and Number(false) return, respectively?
undefined and undefined
NaN and NaN
true and false
1 and 0
What will Number(undefined) and Number(null) return, respectively?
NaN and NaN
0 and 0
undefined and null
NaN and 0
Which of the following is the best name for a boolean variable that checks if a user is allowed to do something on your website?
getPermission
handlePermission
permission
hasPermission
Which of the following is the best name for a function that runs when a user submits a form?
hasSubmitted
formSubmit
didSubmit
handleSubmit
What is a sparse array?
An array where one or more indices have a value of null.
An array where one or more indices have a value of undefined.
An array where one or more indices have a value of an empty object literal.
An array where one or more indices are not assigned a value.
In which of the following examples will arr NOT be a sparse array?
const arr = new Array(5);
const arr = [1, 2, 3];
arr[4] = 4;
const arr = [1, 2, 3, , 5];
const arr = Array.from({ length: 5 });
What is the primary purpose of a linter?
To format code automatically.
To optimize code for performance.
To create documentation for code.
To detect potential errors and issues in code.
What is a benefit of using a formatter in a codebase?
They allow developers to compile code more efficiently.
They convert code to a specific programming language.
They detect logical errors.
They ensure a consistent code style.
In JavaScript, who or what is typically responsible for allocating memory to variables?
The developer.
The operating system.
The server.
The runtime engine.
What will be logged to the console in the following code?
function trackTotal(initialValue) {
let total = initialValue;
return function(increment) {
total += increment;
return total;
};
}
let track = trackTotal(1);
console.log(track(2));
console.log(track(3));
2
5
2
3
5
6
3
6
What is hoisting in JavaScript?
Raising errors to the top of the code.
The process of creating new variables.
Automatically moving var declarations to the top of the block.
The process of moving variable declarations to the top of their scope.
Why is using the var keyword considered bad practice in modern JavaScript?
They're slower than let and const.
They cause syntax errors.
They don't allow type checking.
They're accessible outside their block.
What is the purpose of modules in JavaScript?
To improve code performance.
To make code more difficult to understand.
To create new programming languages.
To organize code into reusable units.
How do you add an app.js script as a module in an HTML document?
<script type="module/javascript" src="app.js"></script>
<script src="app.js"></script>
<script src="app.js" module></script>
<script type="module" src="app.js"></script>
Which of the following examples exports the calculateSum function from a utils.js module and properly imports and uses it in an app.js file?
// utils.js
export default function calculateSum(a, b) {
return a + b;
}
// app.js
import { calculateSum } from './utils.js';
console.log(calculateSum(2, 3));
// utils.js
export function calculateSum(a, b) {
return a + b;
}
// app.js
import calculateSum from './utils.js';
console.log(calculateSum(2, 3));
// utils.js
function calculateSum(a, b) {
return a + b;
}
export default calculateSum;
// app.js
import * as utils from './utils.js';
console.log(utils.calculateSum(2, 3));
// utils.js
export function calculateSum(a, b) {
return a + b;
}
// app.js
import { calculateSum } from './utils.js';
console.log(calculateSum(2, 3));