Complete the code to create a function expression that returns the sum of two numbers.
const add = function(a, b) { return a [1] b; }; console.log(add(2, 3));The + operator adds two numbers. Here, it returns the sum of a and b.
Complete the code to assign an anonymous function to the variable greet that returns 'Hello!'.
const greet = [1]() { return 'Hello!'; }; console.log(greet());
The keyword function defines a function expression in JavaScript.
Fix the error in the function expression syntax.
const multiply = function(a, b) [1] return a * b; }; console.log(multiply(4, 5));
The function body must start with a curly brace { to enclose the statements.
Complete the code to create a function expression that returns the square of a number.
const square = function(num) { return num [1] 2; }; console.log(square(6));* instead of exponentiation **.The function body starts with a curly brace {. The exponentiation operator ** raises num to the power of 2.
Fill both blanks to create a function expression that filters an array to keep only even numbers.
const evens = numbers.filter(function([1]) { return [2] % 2 === 0; }); console.log(evens);
The parameter name is num. The function body starts with a curly brace {. The condition checks if num is even by using the modulo operator.