Podcast
Questions and Answers
Which of the following best describes the scope of a variable declared with var inside a function?
Which of the following best describes the scope of a variable declared with var inside a function?
- Block-scoped
- Function-scoped (correct)
- Globally-scoped if declared within a block
- Lexically scoped
Which of the following statements about let is true?
Which of the following statements about let is true?
- It can be re-assigned and is block-scoped. (correct)
- It must be initialized at the time of declaration and is block-scoped.
- It can be re-assigned and is function-scoped.
- It cannot be re-assigned and is block-scoped.
Which statement about const is correct?
Which statement about const is correct?
- Variables declared with const must be initialized and cannot be re-assigned. (correct)
- Variables declared with const can be re-assigned and are block-scoped.
- Variables declared with const cannot be re-assigned but may be declared without initialization.
- Variables declared with const are function-scoped.
What does hoisting mean in JavaScript?
What does hoisting mean in JavaScript?
What happens if you try to access a let or const variable before its declaration?
What happens if you try to access a let or const variable before its declaration?
Which of the following is a correct rule for naming variables in JavaScript?
Which of the following is a correct rule for naming variables in JavaScript?
Which of the following is a primitive data type in JavaScript?
Which of the following is a primitive data type in JavaScript?
Which statement correctly describes the BigInt data type in JavaScript?
Which statement correctly describes the BigInt data type in JavaScript?
What value does a variable declared with let hold if it is declared but not explicitly initialized (after its declaration line)?
What value does a variable declared with let hold if it is declared but not explicitly initialized (after its declaration line)?
Which of the following is NOT a valid JavaScript variable name?
Which of the following is NOT a valid JavaScript variable name?
Which of the following statements correctly describes the behavior of the var keyword?
Which of the following statements correctly describes the behavior of the var keyword?
Which data type in JavaScript represents the intentional absence of any object value?
Which data type in JavaScript represents the intentional absence of any object value?
Which statement best describes the difference between null and undefined in JavaScript?
Which statement best describes the difference between null and undefined in JavaScript?
What is the output of the following code?
console.log(a);
var a = 5;
What is the output of the following code?
console.log(a); var a = 5;
What is the output of the following code?
console.log(b);
let b = 10;
What is the output of the following code?
console.log(b); let b = 10;
Which statement about hoisting and variable declarations is correct?
Which statement about hoisting and variable declarations is correct?
Which of the following operations would cause a TypeError due to mixing incompatible types?
Which of the following operations would cause a TypeError due to mixing incompatible types?
What is the primary purpose of using the const keyword in JavaScript?
What is the primary purpose of using the const keyword in JavaScript?
Which of the following is a correct example of a template literal in JavaScript?
Which of the following is a correct example of a template literal in JavaScript?
Which of the following statements about type coercion in JavaScript is true?
Which of the following statements about type coercion in JavaScript is true?
What is the output of the following code?
console.log(typeof null);
What is the output of the following code?
console.log(typeof null);
What does the term "temporal dead zone" refer to in JavaScript?
What does the term "temporal dead zone" refer to in JavaScript?
Which operator should you use to ensure that both the value and type are compared in JavaScript?
Which operator should you use to ensure that both the value and type are compared in JavaScript?
Which of the following is considered a non-primitive (object) in JavaScript?
Which of the following is considered a non-primitive (object) in JavaScript?
What happens if you try to re-declare a variable using let in the same block?
What happens if you try to re-declare a variable using let in the same block?
What is the output of the following code?
console.log("5" + 2);
What is the output of the following code?
console.log("5" + 2);
What is the output of the following code?
console.log("5" - 2);
What is the output of the following code?
console.log("5" - 2);
What is the output of the following code?
console.log(0 == false);
What is the output of the following code?
console.log(0 == false);
What is the output of the following code?
console.log(0 === false);
What is the output of the following code?
console.log(0 === false);
Which expression correctly ensures that addition happens before multiplication?
Which expression correctly ensures that addition happens before multiplication?
What is the primary purpose of using parentheses when calling a function in JavaScript?
What is the primary purpose of using parentheses when calling a function in JavaScript?
Which of the following correctly uses parentheses to wrap a condition in an if statement?
Which of the following correctly uses parentheses to wrap a condition in an if statement?
Which construct creates a new variable scope in JavaScript when used with let or const?
Which construct creates a new variable scope in JavaScript when used with let or const?
How can you distinguish between an object literal and a code block when using curly braces?
How can you distinguish between an object literal and a code block when using curly braces?
What does the following code do?
let numbers = [1, 2, 3, 4];
What does the following code do?
let numbers = [1, 2, 3, 4];
How do you access the third element in the array let items = ['a', 'b', 'c', 'd'];?
How do you access the third element in the array let items = ['a', 'b', 'c', 'd'];?
Which of the following is a limitation of using parentheses ( ) in JavaScript?
Which of the following is a limitation of using parentheses ( ) in JavaScript?
When you see the following syntax, what is being created?
let userArray = [{ name: "John", age: 30 }];
When you see the following syntax, what is being created?
let userArray = [{ name: "John", age: 30 }];
What is the role of curly braces in the following if statement?
if (x > 0) {
let message = "Positive";
console.log(message);
}
What is the role of curly braces in the following if statement?
if (x > 0) { let message = "Positive"; console.log(message); }
Which of the following is an example of implicit type coercion in JavaScript?
Which of the following is an example of implicit type coercion in JavaScript?
Implicit type coercion occurs automatically without explicit instructions from the programmer.
Implicit type coercion occurs automatically without explicit instructions from the programmer.
In JavaScript, the === operator checks for both _____ and _____, preventing implicit coercion.
In JavaScript, the === operator checks for both _____ and _____, preventing implicit coercion.
What happens when you run the following JavaScript code?
console.log("6" - 2);
What happens when you run the following JavaScript code?
console.log("6" - 2);
Strongly typed languages like Java and C++ allow implicit coercion between numbers and strings.
Strongly typed languages like Java and C++ allow implicit coercion between numbers and strings.
In JavaScript, using the + operator between a number and a string results in _____, while using -, *, or / usually results in _____.
In JavaScript, using the + operator between a number and a string results in _____, while using -, *, or / usually results in _____.
Which of the following operations will result in implicit type coercion in JavaScript?
Which of the following operations will result in implicit type coercion in JavaScript?
In JavaScript, Number("123") is an example of implicit type coercion.
In JavaScript, Number("123") is an example of implicit type coercion.
The process of manually converting a value from one type to another is called _____.
The process of manually converting a value from one type to another is called _____.
What will the following JavaScript code output?
console.log(10 + true);
What will the following JavaScript code output?
console.log(10 + true);
Primitive types are stored by reference in memory.
Primitive types are stored by reference in memory.
Which of the following are primitive types in JavaScript?
Which of the following are primitive types in JavaScript?
Primitive types are ________, meaning they cannot be changed once created.
Primitive types are ________, meaning they cannot be changed once created.
Non-primitive types are mutable, meaning their values can be modified without creating a new memory allocation.
Non-primitive types are mutable, meaning their values can be modified without creating a new memory allocation.
Which statement correctly describes primitive vs. non-primitive types?
Which statement correctly describes primitive vs. non-primitive types?
Data structures provide a way to organize and store data efficiently so that it can be accessed, modified, and managed effectively.
Data structures provide a way to organize and store data efficiently so that it can be accessed, modified, and managed effectively.
Data structures provide a way to organize and store data so that it can be ________, modified, and managed effectively.
Data structures provide a way to organize and store data so that it can be ________, modified, and managed effectively.
Which of the following best describes one major benefit of choosing an appropriate data structure?
Which of the following best describes one major benefit of choosing an appropriate data structure?
The choice of a data structure does not affect the speed of operations such as search, insertion, and deletion.
The choice of a data structure does not affect the speed of operations such as search, insertion, and deletion.
Which of the following are the three main types of data structures mentioned in the review?
Which of the following are the three main types of data structures mentioned in the review?
Linear data structures are also known as ________ data structures because they are organized sequentially.
Linear data structures are also known as ________ data structures because they are organized sequentially.
Which of the following is an example of a non-linear data structure?
Which of the following is an example of a non-linear data structure?
Hash-based structures typically store data as key-value pairs and are designed for fast lookup operations.
Hash-based structures typically store data as key-value pairs and are designed for fast lookup operations.
Key operations on data structures include insertion, deletion, access/traversal, and ________.
Key operations on data structures include insertion, deletion, access/traversal, and ________.
Data structures determine how data is stored, accessed, and manipulated.
Data structures determine how data is stored, accessed, and manipulated.
Which type of collection is organized by indexes?
Which type of collection is organized by indexes?
Structured data is like having a well-organized filing system where every piece of information is stored in a specific ________.
Structured data is like having a well-organized filing system where every piece of information is stored in a specific ________.
Which of the following is a common use for JSON (JavaScript Object Notation)?
Which of the following is a common use for JSON (JavaScript Object Notation)?
In JSON, keys must always be enclosed in quotes, whereas in JavaScript object literals, quotes are not required for keys.
In JSON, keys must always be enclosed in quotes, whereas in JavaScript object literals, quotes are not required for keys.
Which of the following is NOT a valid JSON data type?
Which of the following is NOT a valid JSON data type?
The equality operator == in JavaScript performs ________ conversion before comparing two values.
The equality operator == in JavaScript performs ________ conversion before comparing two values.
The strict equality operator === compares both the value and the data type of two operands.
The strict equality operator === compares both the value and the data type of two operands.
The strict equality operator === compares both the ________ and the ________ of two operands.
The strict equality operator === compares both the ________ and the ________ of two operands.
Which of the following best describes the overall role of data structures?
Which of the following best describes the overall role of data structures?
What is the main advantage of using the strict equality operator (===) over the loose equality operator (==) in JavaScript?
What is the main advantage of using the strict equality operator (===) over the loose equality operator (==) in JavaScript?
Core to looping is the idea of _____. This means you want to perform the same set of actions many times.
Core to looping is the idea of _____. This means you want to perform the same set of actions many times.
Is the process of going through items one by one (for example, each element in an array).
Is the process of going through items one by one (for example, each element in an array).
Conditional termination means that a loop stops executing when a specified condition changes (or when a break is encountered).
Conditional termination means that a loop stops executing when a specified condition changes (or when a break is encountered).
When should you use a for loop?
When should you use a for loop?
Which loop type is best when the number of iterations is unpredictable and depends on a condition?
Which loop type is best when the number of iterations is unpredictable and depends on a condition?
Which loop guarantees that the code block will run at least once, even if the condition is false from the start?
Which loop guarantees that the code block will run at least once, even if the condition is false from the start?
When iterating over the keys (property names) of an object in JavaScript, which loop should you use
When iterating over the keys (property names) of an object in JavaScript, which loop should you use
If you want to iterate directly over the values of an iterable object (like an array or string), which loop is most suitable?
If you want to iterate directly over the values of an iterable object (like an array or string), which loop is most suitable?
A for loop is best used when you know the number of iterations because it handles initialization, condition, and __________ all together.
A for loop is best used when you know the number of iterations because it handles initialization, condition, and __________ all together.
A while loop may run zero times if the condition is false initially.
A while loop may run zero times if the condition is false initially.
A do...while loop always executes its code block at least once before checking the condition.
A do...while loop always executes its code block at least once before checking the condition.
The loop stops executing when a specified condition changes or a break is encountered; this is called __________ termination.
The loop stops executing when a specified condition changes or a break is encountered; this is called __________ termination.
Which statement best distinguishes sequences, selections, and loops?
Which statement best distinguishes sequences, selections, and loops?
A ______ statement is used to immediately exit a loop before its condition naturally becomes false.
A ______ statement is used to immediately exit a loop before its condition naturally becomes false.
Which loop is best when you know the exact number of iterations you need, such as processing every element in a fixed-size array?
Which loop is best when you know the exact number of iterations you need, such as processing every element in a fixed-size array?
Which loop should you use when you need to guarantee that a code block runs at least once, even if the condition is initially false?
Which loop should you use when you need to guarantee that a code block runs at least once, even if the condition is initially false?
The for...in loop is primarily used to iterate over arrays.
The for...in loop is primarily used to iterate over arrays.
The for...of loop iterates directly over the values of an iterable object, making it ideal for arrays and strings.
The for...of loop iterates directly over the values of an iterable object, making it ideal for arrays and strings.
A loop stops executing when its condition becomes __________.
A loop stops executing when its condition becomes __________.
In the context of looping, the process of going through each item in a set one by one is called:
In the context of looping, the process of going through each item in a set one by one is called:
A semicolons is required after a statement in JavaScript.
A semicolons is required after a statement in JavaScript.
How many statements are present inside the function block?
function genie() {
let a, b, c;
a = 5;
b = 9;
c = a + b;
}
How many statements are present inside the function block?
function genie() { let a, b, c; a = 5; b = 9; c = a + b; }
What will be the alerted result?
let x = 5;
x = 7;
x = x + x;
alert(x);
What will be the alerted result?
let x = 5; x = 7; x = x + x; alert(x);
With the let keyword, you can declare variables with the same name in the same block.
With the let keyword, you can declare variables with the same name in the same block.
The break statement can be used to exit any block of code, including functions, if statements, and loops.
The break statement can be used to exit any block of code, including functions, if statements, and loops.
What is the primary difference between using return and break inside a loop that is inside a function?
What is the primary difference between using return and break inside a loop that is inside a function?
In JavaScript, the __________ statement is used to immediately exit a loop or switch statement, while the __________ statement is used to exit a function and optionally return a value.
In JavaScript, the __________ statement is used to immediately exit a loop or switch statement, while the __________ statement is used to exit a function and optionally return a value.
Using return inside a loop will exit the loop but continue executing any code after the loop in the same function.
Using return inside a loop will exit the loop but continue executing any code after the loop in the same function.
Which of the following statements is correct about the break statement?
Which of the following statements is correct about the break statement?
The return statement cannot be used outside of a function.
The return statement cannot be used outside of a function.
Consider the following code:
function testLoop() {
for (let i = 0; i < 5; i++) {
if (i === 3) {
break;
}
console.log(i);
}
console.log("Loop ended");
}
testLoop();
Consider the following code:
function testLoop() { for (let i = 0; i < 5; i++) { if (i === 3) { break; } console.log(i); } console.log("Loop ended"); } testLoop();
When a return statement is executed inside a function, it immediately terminates the function's execution and optionally returns __________.
When a return statement is executed inside a function, it immediately terminates the function's execution and optionally returns __________.
If you want to exit a loop early without stopping the execution of the rest of the function, you should use:
If you want to exit a loop early without stopping the execution of the rest of the function, you should use:
Using break in a switch statement prevents the execution from "falling through" to subsequent cases.
Using break in a switch statement prevents the execution from "falling through" to subsequent cases.
Flashcards
Capital of France (example flashcard)
Capital of France (example flashcard)
Paris
Study Notes
Glossary
Type Conversion & Coercion
Implicit Conversion (Coercion):
- Definition: The automatic conversion of values from one data type to another by the compiler or interpreter.
- Context: Happens without explicit direction from the programmer (e.g., converting a number to a string during concatenation).
- Key Point: Usually a safe conversion (often converting from a smaller to a larger type) with no data loss.
Explicit Conversion (Casting):
- Definition: The manual conversion of values from one type to another, as directed by the programmer.
- Context: Used when converting from a larger type to a smaller type or when implicit coercion isn’t acceptable.
- Key Point: Can cause data loss; used only when needed.
Conversion vs. Coercion:
- Conversion: Generally refers to explicit, manual conversion (casting).
- Coercion: Often used to describe implicit, automatic type conversion.
Core Concepts of Looping
Repetition:
- Definition: Performing the same set of actions multiple times.
- Context: The foundational idea behind loops—repeat tasks until a condition is met.
Iteration:
- Definition: The process of going through items one by one (e.g., elements in an array or properties of an object).
- Context: Iteration is used to process each element in a collection sequentially.
Conditional Termination:
- Definition: The loop stops executing when a specified condition changes (or when a break statement is encountered).
- Context: All loops check a condition to decide whether to continue or stop.
Looping Constructs
For Loop:
- Definition: A loop that integrates initialization, condition-checking, and updating in one statement.
- Usage: Use when you know in advance how many iterations are required or when you need an index counter (e.g., iterating over an array).
- Analogy: Counting items on a checklist when you know the exact number.
While Loop:
- Definition: A loop that executes its block of code as long as a condition is true.
- Usage: Use when the number of iterations isn’t known in advance and depends on dynamic conditions.
- Analogy: Continuing to search until you no longer find what you’re looking for.
Do...While Loop:
- Definition: A loop that executes its code block at least once before checking the condition.
- Usage: Use when the code should run at least once (e.g., prompting a user for input) regardless of the initial condition.
- Key Phrase: "Do the code, then check if we should do it again."
For...in Loop:
- Definition: A loop used to iterate over the enumerable property keys of an object.
- Usage: Ideal for when you need to process each key in an object rather than iterating over an array’s values.
For...of Loop:
- Definition: A loop used to iterate directly over the values of an iterable object (like arrays, strings, etc.).
- Usage: Provides a cleaner syntax when you want to work directly with the elements (values) rather than their indices.
Break Statement:
- Definition: A control statement used to exit a loop immediately, regardless of whether its condition is still true.
- Usage: Use when you want to stop iterating early once a specific condition is met.
Other Loop-Related Terms
Sequences:
- Definition: A specific, linear order in which statements or tasks are executed.
- Context: In programming, sequences ensure that code runs in a predetermined, step-by-step order.
Selections:
- Definition: Conditional constructs (e.g., if/else, switch) that allow the program to choose between multiple paths based on different conditions.
- Context: Also known as branching, similar to a tree with many branches.
Loops:
- Definition: Constructs that enable the repetitive execution of a block of code until a condition changes.
- Context: Combine repetition, iteration, and conditional termination to automate repetitive tasks.
Data Structures & Related Concepts
Purpose of Data Structures:
- Definition: Data structures provide a way to organize and store data so that it can be efficiently accessed, modified, and managed.
- Key Points:
- Organization & Storage: They structure data in an orderly fashion.
- Efficiency: The choice of data structure affects the performance of operations such as searching, insertion, and deletion.
Types of Data Structures:
- Linear Data Structures: Organized sequentially (e.g., arrays, linked lists).
- Non-Linear Data Structures: Organized hierarchically or as networks (e.g., trees, graphs).
- Hash-Based Structures: Use key-value pairs for fast lookups (e.g., hash tables, dictionaries).
Key Operations on Data Structures:
- Insertion: Adding data to the structure.
- Deletion: Removing data from the structure.
- Access/Traversal: Retrieving or navigating through data.
- Searching: Locating data within the structure.
Indexed Collections vs. Keyed Collections:
- Indexed Collections: Organized by position (e.g., arrays).
- Keyed Collections: Organized by keys (e.g., objects, dictionaries).
Structured Data:
- Definition: Data organized in a systematic way (like a well-organized filing system).
- Context: Makes data easy to locate and manage.
JSON (JavaScript Object Notation)
Definition:
- A lightweight data representation format used primarily for APIs and configuration files.
Characteristics:
- Human-readable and easy to write.
- Similar to XML or YAML but often preferred for its simplicity.
- Note on Keys: JSON requires keys to be in quotes, whereas JavaScript objects may omit quotes for keys if they are valid identifiers.
JSON Data Types:
- Strings, Numbers, Booleans, Null, Arrays, Objects.
Equality Comparison
== (Loose Equality):
- Definition: An equality operator that performs type conversion (coercion) before comparing two values.
- Context: Can lead to unexpected results due to automatic conversion.
=== (Strict Equality):
- Definition: An equality operator that compares both value and data type without performing type conversion.
- Context: Returns true only if both the value and type are identical.
Additional Concepts
Variable Declaration:
- Definition: The process of creating a variable to store data.
- Context: Involves keywords such as
var
,let
, orconst
in JavaScript.
Hoisting:
- Definition: A JavaScript mechanism where variable and function declarations are moved to the top of their containing scope during compilation.
- Context: Affects how and when variables are available in your code.
Temporal Dead Zone (TDZ):
- Definition: The time span between entering a block and the point where a variable declared with
let
orconst
is initialized, during which the variable cannot be accessed. - Context: Ensures that variables are not accessed before they are declared and initialized.
Variable Naming Rules:
- Definition: The conventions and rules for naming variables in a programming language (e.g., must start with a letter, underscore, or dollar sign in JavaScript; case-sensitive; no reserved keywords).
- Context: Ensures clarity and prevents conflicts with language syntax.
Template Literals:
- Definition: A way to define strings in JavaScript using backticks (
`
) that allow for embedded expressions (e.g.,${variable}
) and multi-line strings. - Context: Provides a more readable and concise method for string interpolation and formatting compared to traditional concatenation.
Data Types:
-
Primitive Types:
- Definition: Basic data types that are stored by value and are immutable (e.g., Number, String, Boolean, Null, Undefined, Symbol, BigInt).
- Analogy: Like a built-in memory card that is read-only.
-
Non-Primitive Types:
- Definition: Complex data structures that are stored by reference and are mutable (e.g., Objects, Arrays, Functions).
- Analogy: Like a temporary memory card that can be modified.
Type Casting / Conversion:
- Definition: Changing a variable from one data type to another, either implicitly (coercion) or explicitly (casting).
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.