-
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
this
An arrow function is a compact alternative to traditional function expressions. It has no this
, no arguments
, no super
, and no new.target
bindings.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const add = (a, b) => a + b;
Feature | Regular Function | Arrow Function |
---|---|---|
this binding |
Dynamic (based on caller) | Lexical (based on surrounding scope) |
arguments object |
Available | Not available |
Constructor support | Can be used with new |
❌ Cannot be used as constructor |
const greet = name => `Hello, ${name}`;
console.log(greet("Amit")); // Hello, Amit
const multiply = (x, y) => {
return x * y;
};
const numbers = [1, 2, 3, 4];
const squares = numbers.map(n => n * n);
console.log(squares); // [1, 4, 9, 16]
Q1. Write an arrow function double(x)
that returns double the input. Call it with 10
.
Q2. Create an arrow function greet(name)
that returns "Hello, name"
. Test it with "Riya"
.
Q3. Convert this regular function to arrow function:
function sum(a, b) {
return a + b;
}
Q4. Use an arrow function to map over [1, 2, 3]
and return their cubes.
Q5. Create an arrow function isEven(num)
that returns true
if the number is even.
Q6. Write an arrow function inside setTimeout
that prints "Hi after 1 second"
after 1000ms.
Q7. Write an arrow function filterWords(words)
that filters all words longer than 4 letters from an array.
Q8. Create a function getFullName
that takes first
and last
names and returns full name using an arrow function.
Q9. Create a function that returns another arrow function to multiply a number by a fixed multiplier. Test it.
Q10. Inside an object method, use an arrow function as a callback to preserve this
when using setTimeout
.
Q1: What is a main feature of arrow functions?
Q2: Which of the following is a correct arrow function?
Q3: Can arrow functions be used as constructors with new?
Q4: Arrow functions automatically return the result if:
Q5: Do arrow functions have their own arguments object?
Q6: How do arrow functions handle this?
Q7: Which of these is NOT true about arrow functions?