JS Basic Flashcards
What is a function in JavaScript?
A function is a block of code designed to perform a particular task.
True or False: Functions in JavaScript can be assigned to variables.
True
Fill in the blank: A function can be defined using the ______ keyword.
function
What is the syntax to declare a function named ‘myFunction’?
function myFunction() {}
What are function parameters?
Function parameters are the variables listed within the parentheses in a function declaration.
What is the purpose of the ‘return’ statement in a function?
The ‘return’ statement is used to exit a function and return a value to the caller.
What type of function is defined using the arrow syntax?
Arrow function
True or False: Functions can be nested inside other functions.
True
What is a callback function?
A callback function is a function passed into another function as an argument to be executed later.
How do you invoke a function named ‘calculate’?
calculate();
What is a higher-order function?
A higher-order function is a function that takes another function as an argument or returns a function as a result.
What does the ‘this’ keyword refer to inside a function?
‘this’ refers to the object that is executing the current function.
What is the difference between function declaration and function expression?
Function declarations are hoisted, while function expressions are not.
Fill in the blank: A function can be invoked using ______ or ______.
function name; function expression
What is an Immediately Invoked Function Expression (IIFE)?
An IIFE is a function that runs as soon as it is defined.
True or False: You can have multiple return statements in a single function.
True
What is the purpose of the ‘arguments’ object in functions?
The ‘arguments’ object is an array-like object that contains the values of the arguments passed to a function.
What does the term ‘scope’ refer to in JavaScript?
Scope refers to the accessibility of variables and functions in different parts of the code.
What is a default parameter in a function?
A default parameter is a parameter that has a default value if no value is passed.
What is closure in JavaScript?
Closure is a feature where an inner function has access to the outer function’s variables even after the outer function has returned.