Class Session
Class Session
30-7-2025
JavaScript Functions & Methods
क्
Code/Type नाम / प्रकार विवरण (हिंदी में)
र.
सामान्य तरीका function define
function hello() { ... Function Declaration /
1. } करने का; इसे कहीं से भी call
Statement किया जा सकता है।
function demo(a, b) Parameter Function / दो arguments लेता है और उनका
2. { ... } जोड़ दिखाता है।
Expression
IIFE (Immediately Invoked जो function तुरंत define होते
3. (function(){ ... })() ही खुद-ब-खुद run हो जाता है।
Function Expression)
Short syntax; एक parameter लेता
let data = (s) => Arrow Function (with
4. { return s**5 } है और उसका power 5 निकालता
block) है।
दो parameters लेता है और सीधे
let hello = (x, y) =>
5. x + y Arrow Function (one-line) उनका जोड़ return करता है (short
syntax)।
let hello1 = () => Arrow Function (no कोई parameter नहीं लेता; सीधा
6. 'hello world' string return करता है।
params)
arr.map((val) => val + हर element पर function apply करता
7. 5) Array Method – map() है और नया array return करता है।
जो elements condition को pass
arr.filter((val) =>
8. val > 50) Array Method – filter() करते हैं, सिर्फ उन्हें return
करता है।
सभी values को एक ही value में
arr.reduce((p, c) => p
9. * c) Array Method – reduce() बदल देता है (जैसे sum, product,
etc.)।
JavaScript Object
No. Code / Method Purpose Behavior / Result
Declares an object with Creates an object: {name:
1 let obj = { ... } 'madhura', city: 'pune', age:
key-value pairs 27}
Returns all the keys of the
2 Object.keys(obj) Output: ['name', 'city', 'age']
object as an array
Returns all the values of
3 Object.values(obj) Output: ['madhura', 'pune', 27]
the object as an array
Copies the object into a obj1 = Object.assign(obj)
4 Object.assign(obj)
creates a shallow copy of obj
new object
obj1.name = 'Rahi' Updates values in the obj1 becomes: { name: 'Rahi',
city: 'Banglore', age: 25,
etc. copied object company: 'TCS' }
Freezes the object – no
Any modification on obj1 will be
5 Object.freeze(obj) add/update/delete is
ignored silently in non-strict mode
allowed
obj1.name = 'Rahi' ❌ Change will not happen obj1.name will still be 'madhura'
Seals the object – update
You can change existing keys, but
6 Object.seal(obj) is allowed, but no
can't add or remove properties
add/delete
obj1.name = 'Rahi' ✅ Update works name will now be 'Rahi'
obj1.company = Property company won't be added to
'TCS' ❌ Won’t be added
the object
30-7-2025
JAVASCRIPT STRING FUNCTION
Output (for given
Variable Method Used Description
string)
Returns the total
a str.length
number of 41
characters in the
string
Converts all "JAVASCRIPT IS A
b str.toUpperCase() characters to BEST FRONTEND
uppercase LANGUAGE."
Converts all "javascript is a
c str.toLowerCase() characters to best frontend
lowercase language."
d str.startsWith('J')
Checks if string true
starts with 'J'
e str.endsWith('age.')
Checks if string true
ends with "age."
Replaces
"React is a best
f str.replace('Javascript','React') "Javascript"
frontend language."
with "React"
Extracts
"ascript is a best
g str.slice(3, 35) characters from frontend lang"
index 3 to 34
Splits the string ["Javascript", "",
"is", "a", "best",
h str.split(" ") into an array by "frontend",
space "language."]
Returns the
i str.charAt(10) character at " " (space character)
index 10
Method
# Description Example Output
Used
Transforms each element of the [6,7,8,9,10,11,12,13] (adds 5 to
1 map()
array. each element)
Method
# Description Example Output
Used
2 filter() Filters elements based on condition. [59, 83] (values > 50)
Reduces array to single value by
3 reduce() 40320
multiplying all elements.
Method /
# Description Example Output / Behavior
Pattern
Combines two arrays using concat
10 apply() [2,4,5,6,11,12,13]
+ apply.
Binds function context to another My name is dipti and I got 90
11 bind() % in the exam
object (changes this).
Calls constructor function with
12 call() 1 rohan, 2 riya
another constructor's context.
Converts String object to string
13 toString() 'good morning everyone'
primitive.
1-8-2025
JavaScript Number Methods
a Number.parseInt(data)
Converts to integer (removes 23
decimals)
b Number.parseFloat(data)
Keeps decimal (converts to 23.676
float)
c Number.isInteger(data) Checks if value is an integer false
d Number.isFinite(data)
Checks if value is a finite true
number
e data.toFixed(5)
Returns string with 5 decimal "23.67600"
places
f data.toPrecision(6)
Returns number as a string with "23.6760"
6 total digits precision
getMonth() + 1
Returns current month (0–11, +1 8
to correct)
getFullYear() Returns 4-digit year 2025
Returns day of the week (0–6,
getDay() 2 (Tuesday)
Sunday = 0)
getHours() Current hour (0–23) 15
getMinutes() Current minutes (0–59) 30
getSeconds() Current seconds (0–59) 12
getMilliseconds() Current milliseconds (0–999) 482
setDate(3) Sets day of the month 3
setFullYear(2027) Sets the year 2027
setMonth(5)
Sets month to June (0-based 6
index)
Format Example Custom date format with concat 8/5/2025
data elements
Selects 3rd
<p>
Used to apply styling to this
2 element[2] Index access element
specific element
(index starts
at 0)
Changes
element[2].style.backgroundColor = Inline Style
3 background Only one style applied
'red' (commented) (single)
color to red
color: yellow,
Sets
background: blue,
Inline Style multiple
4 element[2].style.cssText = "..." font-size: 50px,
(multiple) CSS
border: 7px solid red
properties
applied at once
Form-Related Events
Event Attribute Triggered When...
Mouse Events
Keyboard Events
Event Attribute Triggered When...
Clipboard Events
Event Attribute Triggered When...
✅ Window Events
Event Attribute Triggered When...
✅ Miscellaneous Events
Event Attribute Triggered When...
5-8-2025(tUesDAY)
JavaScript DOM & Math Methods – Summary Table
# Code / Concept Method / Property Type Description / Action
element.setAttribute('href', DOM Sets or updates an attribute
1 URL)
setAttribute()
Attribute (e.g., href) on an element
DOM Gets the value of the specified
2 element.getAttribute('title') getAttribute()
Attribute attribute
addEventListener('click', Event Adds an event listener (non-
3 function(){})
addEventListener()
Handling inline), e.g., on click
Event Triggers a function when an
4 onclick="functionName()" onclick (inline)
Handling element is clicked
Timing Calls a function every ms
5 setInterval(function, ms) setInterval()
Function milliseconds until cleared
# Code / Concept Method / Property Type Description / Action
Timing Stops the interval set by
6 clearInterval(intervalID) clearInterval()
Function setInterval()
Executes a function once after
Timing
7 setTimeout(function, ms) setTimeout() a specified delay in
Function
milliseconds
Timing Cancels a timeout set by
8 clearTimeout(timeoutID) clearTimeout()
Function setTimeout() before it runs
Dynamically changes the
DOM
9 style.marginLeft = x + 'px' style manipulation inline CSS style (e.g.,
Styling
movement animation)
Math Rounds up to the nearest
10 Math.ceil(-4.456) Math.ceil()
Object integer
Math Rounds down to the nearest
11 Math.floor(4.456) Math.floor()
Object integer
Math Returns a random float
12 Math.random() * 100 Math.random()
Object between 0 and 100
6-8-2025(Wednesday) –
clearTimeout()
// Schedule a timeout
let timer = setTimeout(() => {
console.log("This will not run if cleared in time.");
}, 3000);