Loading

Quipoin Menu

Learn • Practice • Grow

java-script / Function in JS
interview

Q1. What is a function in JavaScript?
A function in JavaScript is a block of reusable code designed to perform a specific task.
Functions help avoid repeating the same code multiple times. They improve code readability, reusability, and organization.

Example
function greet() {
  return "Hello World";
}

console.log(greet());


Q2. Why are functions important?
Functions are important because they help in organizing code, improving reusability, and reducing duplication.
They allow developers to break large programs into smaller, manageable parts.


Q3. How do you define a Function in JavaScript?
A function is defined using the function keyword followed by the function name, parentheses, and curly braces.

Example
function add(a, b) {
  return a + b;
}


Q4. What is Function Declaration?
Function declaration is a method of creating a function using the function keyword.

Example
function sayHello() {
  console.log("Hello");
}

Function declarations are hoisted, meaning they can be used before they are declared.


Q5. What is Function Expression?
A function expression is when a function is assigned to a variable.

Example
const multiply = function(a, b) {
  return a * b;
};

Function expressions are not hoisted like function declarations.