JavaScript function syntax, event handling, and basic DOM manipulation methods explained with a short example each.
42 cards · basic cards · AI-written, checked twice. Edit anything.
- What is the syntax for a basic function declaration in JavaScript?
- function functionName(parameters) { return value; }
- How do you write a function expression?
- const functionName = function(parameters) { return value; };
- What is the arrow function syntax?
- const functionName = (parameters) => { return value; };
- What does a return statement do in a function?
- It exits the function and sends back a value to the caller.
- How do you set a default parameter value in a function?
- function greet(name = 'Guest') { return 'Hello ' + name; }
- What does the rest parameter (...) allow a function to do?
- Accept a variable number of arguments as an array.
- What is function scope in JavaScript?
- Variables declared inside a function are only accessible within that function.
- What is a closure?
- A function that has access to variables from its outer function's scope even after that outer function has returned.
- What is a callback function?
- A function passed as an argument to another function, to be executed later.
- What is an anonymous function?
- A function without a name, often used as a callback or stored in a variable.
- What is an IIFE (Immediately Invoked Function Expression)?
- (function() { code here })(); - a function that runs immediately upon definition.
- What is function hoisting?
- Function declarations are moved to the top of their scope before code execution, so they can be called before they are defined.
- What does the bind() method do?
- It creates a new function with a fixed this context and optional pre-filled arguments.
- What does the call() method do?
- It invokes a function with a specified this context and arguments passed individually.
- What does the apply() method do?
- It invokes a function with a specified this context and arguments passed as an array.