-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JS Basics
JS Variables & Operators
JS Data Types & Conversion
JS Numbers & Math
JS Strings
JS Dates
JS Arrays
JS Control Flow
JS Loops & Iteration
JS Functions
JS Functions
Function Definitions
Function Parameters
Function Invocation
Function Call
Function Apply
Function Bind
Function Closures
JS Arrow Function
JS Objects
JS Objects
JS Object Properties
JS Object Methods
JS Object Display
JS Object Constructors
Object Definitions
Object Get / Set
Object Prototypes
Object Protection
JS Classes & Modules
JS Async Programming
JS Advanced
JS Destructuring
JS Bitwise
JS RegExp
JS Precedence
JS Errors
JS Scope
JS Hoisting
JS Strict Mode
JS this Keyword
JS HTML DOM
DOM Intro
DOM Methods
DOM Document
DOM Elements
DOM HTML
DOM Forms
DOM CSS
DOM Animations
DOM Events
DOM Event Listener
DOM Navigation
DOM Nodes
DOM Collections
DOM Node Lists
JS BOM (Browser Object Model)
JS Window
JS Screen
JS Location
JS History
JS Navigator
JS Popup Alert
JS Timing
JS Cookies
Web Storage API
JS Web APIs
JS AJAX
AJAX Intro
AJAX XMLHttp
AJAX Request
AJAX Response
AJAX XML File
AJAX PHP
AJAX ASP
AJAX Database
AJAX Applications
AJAX Examples
JS JSON
JSON Intro
JSON Syntax
JSON vs XML
JSON Data Types
JSON Parse
JSON Stringify
JSON Objects
JSON Arrays
JSON Server
JSON PHP
JSON HTML
JSON JSONP
JS Canvas
JS Graphics & Charts
JavaScript supports multiple ways to define a function. Each has its own use-case, scope rules, and behavior.
✅ Most common way to define a named function.
function greet(name) {
return "Hello, " + name;
}
Hoisted (can be used before it’s defined).
Can be reused multiple times.
✅ A function assigned to a variable.
const add = function(a, b) {
return a + b;
};
Not hoisted.
Useful when passing functions as values (like in callbacks).
✅ Shorter syntax and no own this
.
const multiply = (x, y) => x * y;
Ideal for one-liners or functional programming.
Cannot be used as constructors.
No arguments
object or this
binding.
✅ Rarely used; not recommended due to security and performance concerns.
const subtract = new Function("a", "b", "return a - b");
console.log(subtract(10, 5)); // Output: 5
Named function has a name: function sayHi() {}
Anonymous function does not have a name: function() {}
Often used in expressions or as arguments to other functions.
// Declaration
function square(x) {
return x * x;
}
// Expression
const squareExpr = function(x) {
return x * x;
};
// Arrow
const squareArrow = x => x * x;
Q1. What is a function declaration and how is it different from a function expression?
Q2. How do arrow functions handle the this
keyword differently than regular functions?
Q3. What is a function expression and when should you use it?
Q4. Can a function expression be named? Show an example.
Q5. Write a function using all three: declaration, expression, and arrow syntax for adding two numbers.
Q6. Is a function declaration hoisted in JavaScript? Explain with an example.
Q7. What is the purpose of the Function
constructor, and why is it rarely used?
Q8. What are the risks of using the Function
constructor in JavaScript?
Q9. Can an arrow function be used as a constructor? Why or why not?
Q10. Write an arrow function that returns the square of a number, and a function expression that returns its cube.
Q1: Which is a function declaration?
Q2: Which function type is hoisted?
Q3: Which function type does NOT have its own this?
Q4: What is a valid arrow function syntax?
Q5: Which function type is commonly used in callbacks and event handlers?
Q6: Can a function expression be anonymous?
Q7: Which of the following is discouraged for defining functions due to security risks?