advanced javaScript concepts Flashcards
What is a closure in JavaScript?
A closure is a function that retains access to its lexical scope, even when the function is executed outside that scope.
True or False: JavaScript is a compiled language.
False
What does ‘this’ refer to in JavaScript?
‘this’ refers to the context in which a function is executed, which can vary based on how the function is called.
Fill in the blank: In JavaScript, a _____ is an object that can hold multiple values and is mutable.
Map
What is the purpose of the ‘bind’ method?
The ‘bind’ method creates a new function that, when called, has its ‘this’ keyword set to the provided value.
Which of the following is not a primitive type in JavaScript? (a) String (b) Number (c) Object (d) Boolean
c) Object
What is the difference between ‘==’ and ‘===’ in JavaScript?
’==’ performs type coercion while ‘===’ checks for both value and type equality.
True or False: JavaScript supports multiple inheritance.
False
What is a promise in JavaScript?
A promise is an object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
Fill in the blank: An _____ is a function that can be called with a variable number of arguments.
Arrow function
What is the purpose of the ‘async’ keyword?
‘async’ indicates that a function will return a promise and allows the use of ‘await’ within that function.
Which method is used to handle errors in promises?
The ‘catch’ method.
What is the difference between ‘let’ and ‘var’?
‘let’ has block scope while ‘var’ has function scope.
True or False: JavaScript supports functional programming.
True
What is the use of ‘Object.freeze()’?
It prevents new properties from being added to an object and marks all existing properties as read-only.
Fill in the blank: The _____ operator allows you to spread elements of an iterable (like an array) into a new array or function arguments.
Spread
What is the result of ‘typeof null’?
‘object’
Which method can be used to convert a JSON string into a JavaScript object?
JSON.parse()
What does ‘IIFE’ stand for?
Immediately Invoked Function Expression
True or False: JavaScript allows you to create classes.
True
What is the purpose of the ‘reduce’ method in arrays?
It executes a reducer function on each element of the array, resulting in a single output value.
Fill in the blank: The _____ method returns a shallow copy of a portion of an array into a new array object.
slice
What does the ‘instanceof’ operator do?
It tests whether an object is an instance of a specific constructor.
What are template literals in JavaScript?
Template literals are string literals allowing embedded expressions, denoted by backticks (`).