1/49
A set of flashcards covering core concepts in JavaScript.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the primary purpose of the Console Object in JavaScript?
To serve as a debugging tool that shows runtime execution and logs information.
Which console method is used for logging errors?
console.error()
Which console method is best for measuring performance of code execution?
console.time() and console.timeEnd()
What is the primary advantage of using console.table()?
It displays data in a tabular format for easier reading.
What is the main difference between 'let' and 'var' in JavaScript?
'let' is block-scoped while 'var' is function-scoped.
Which of the following is true about 'const'?
It prevents reassignment of the variable but object properties can still be modified.
What does hoisting in JavaScript refer to?
A mechanism where variable and function declarations are processed before code execution.
Which of the following is a valid use of the 'const' declaration?
const x = {name: 'John'}; x.name = 'Jane';
Which of the following is NOT a primitive data type in JavaScript?
Array.
What is the result of typeof null in JavaScript?
"object".
Which data type is used for representing very large integers beyond the limits of Number?
BigInt.
What is the main difference between null and undefined?
null represents an intentional absence of value, while undefined indicates a variable has been declared but not assigned a value.
What is the result of '5' + 3 in JavaScript?
'53'.
What does the === operator check for?
Value and type equality (strict equality).
What are 'falsy' values in JavaScript?
false, 0, empty strings, null, undefined, and NaN.
What is short-circuit evaluation in JavaScript?
Using && and || operators to conditionally execute code based on truthiness.
What is a higher-order function?
A function that takes another function as an argument or returns a function.
What is the difference between function declarations and function expressions?
Function declarations can be called before they're defined (hoisted), while function expressions cannot.
What is a pure function?
A function that always returns the same output for the same input and has no side effects.
What is a valid arrow function that adds two numbers?
const add = (a, b) => a + b.
What method would you use to create a new array with elements that pass a test?
array.filter().
What is the correct way to access a property named 'user-id' in an object?
obj['user-id'].
What does the spread operator (…) do when used with arrays?
Expands an array into individual elements.
Which array method would you use to transform each element in an array into a new value?
map().
What is destructuring in JavaScript?
A technique to extract values from arrays or properties from objects into distinct variables.
What is the purpose of the constructor() method in a class?
To initialize new object instances of the class.
What does the 'extends' keyword do in a class declaration?
Creates a child class that inherits from a parent class.
What is the 'super' keyword used for in a class?
To call methods from the parent class or constructor.
What is a static method in a class?
A method that is called on the class itself, not on instances.
What is the main difference between a class and a constructor function in JavaScript?
Classes are just syntactic sugar over constructor functions and prototypal inheritance.
What is the primary purpose of JavaScript modules?
To organize code, encapsulate functionality, and manage dependencies.
What is the difference between named exports and default exports?
Named exports can export multiple values, while default exports can only export one value per module.
What is the correct way to import a default export?
import name from './file.js'.
What are namespace imports in JavaScript modules?
Importing all exports from a module into a single object.
What is the difference between querySelector() and getElementById()?
querySelector() can select elements using CSS selectors, while getElementById() only selects by ID.
What is the difference between textContent and innerHTML?
innerHTML can read and update HTML content, while textContent only deals with plain text.
What is event delegation in JavaScript?
Adding a single event listener to a parent element that handles events for its children.
What does the classList property provide?
A way to add, remove, and toggle classes on an element.
What is a Promise in JavaScript?
An object that represents the eventual completion or failure of an asynchronous operation.
What is the purpose of the 'await' keyword?
To pause execution until a Promise is resolved.
How do you handle errors in async/await code?
Using try/catch blocks.
What is the callback hell problem?
When nested callbacks become unmanageable, creating deeply nested code.
What is the purpose of JSON.stringify()?
To convert a JavaScript object into a JSON string.
What does the fetch API return initially?
A Promise that resolves to the Response object.
What is the correct way to parse a JSON string into a JavaScript object?
JSON.parse().
What is the main advantage of using Promise.all()?
It handles multiple promises together and waits for all of them to resolve.
What do we call the state of a Promise before it is either fulfilled or rejected?
Pending.
Which HTTP method is used by default in the fetch API?
GET.
What is the difference between synchronous and asynchronous code execution?
Synchronous code blocks execution until completed, while asynchronous code allows other code to run while waiting.
What is the purpose of Promise.race()?
To return the result of the first promise that resolves or rejects.