0% found this document useful (0 votes)
18 views

My-Own-Note-js

Uploaded by

munnugaming48
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

My-Own-Note-js

Uploaded by

munnugaming48
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Factory Function

It is a function that creates and return an object


Expl-

Basic Syntax of a Factory Function


function createObject(property1,
property2) {
return {
property1: property1,
property2: property2,
method() {
console.log(`Property1 is $
{this.property1}, Property2 is $
{this.property2}`);
}
};
}
Example 1: Creating Objects
Here’s a simple example of a factory function to
create person objects:
javascript
Copy code
function createPerson(name, age) {
return {
name: name,
age: age,
greet() {
console.log(`Hello, my name is $
{this.name} and I am ${this.age} years old.`);
}
};
}

const person1 = createPerson("Alice", 25);


const person2 = createPerson("Bob", 30);

person1.greet(); // Output: Hello, my name is


Alice and I am 25 years old.
person2.greet(); // Output: Hello, my name is Bob
and I am 30 years old.

Destructring Object
It is to extract properties from an object and
assign to it
Exp-
Let a = {
Name:”Hello”,
Age: 18,
Hobbie: “Gaming”
}
Const {Name,Age} = a;

Callback

It is function passed as argument and execute


when we need it
Call back Hell

Nested ayittu callback varumbo difficult to read


and inversion control varum ithinaanu callback
hell

Arrow function

It’s a shorter way to create a function


Basic syntax
const functionName = (parameters) => {
// function body
return value;
};

 If the function body has only one statement,


you can omit the curly braces {} and the
return keyword.
 For single-parameter functions, you can omit
the parentheses () around the parameter.
Single line akumbo curly brace venda multi-line
akumbol venam

Closure

Closure ennu parayunnath javascriptile concept


aanu ath functional scopilulla variable remember
cheyyum even if the function executed
Expl-

function parentFunction() {
let count = 0; // Parent scope variable

function childFunction() {
count++; // Access parent variable
console.log("Count is:", count);
}

return childFunction;
}

const myClosure = parentFunction(); //


parentFunction run cheyyunnu
myClosure(); // Output: Count is: 1
myClosure(); // Output: Count is: 2

Hoisting
Hoisting javascriptile oru behaviour aanu, ithil
variable/function scopeinte topil move
cheyyapettath pole behave cheyyum. Functions
initialize cheyyunnathinu munpe access cheyyan
pattum. Pakshe, var variables undefined aayittu
initialize cheyyum, let and const variables access
cheyyumbol initializationinu munpe error varum

Rest parameter (…args)


Ith use cheyyunath ippol nammuk ethra
argument und ennu ariyilla appol ethra argument
undo athellam store cheyyan use cheyyunnath
aanu rest parameter
Expl-
function sum(...numbers) {
return numbers.reduce((total, num) => total +
num, 0);
}

console.log(sum(1, 2, 3)); // Output: 6


console.log(sum(5, 10, 15, 20)); // Output: 50

CALLSTACK
Callstack ennu parayunnath javascriptile
mechanism aanu ith function execute
cheyyunnath track cheyyan sahayikum

IMMEDIATELY INVOKING FUNCTION


EXECUTION(IIFE)
Self ayittu function invoke cheyyunathaanu iife
(function(){
Console.log(“hi”)
})()
ILLEGAL SHADOWING
Illegal shadowing ennathu JavaScript-il varum,
nammal oru variable aanu declare cheyyunnathu,
athinte same name ulla oru variable um already
outer scope-il undayirikkunnu, pinne athu JS rules
violate cheyyumbo undakunnath annu.
Polyfill
polyfill ennu parayunnath new es6 features old
browseril load avilla ath load cheypikkan same
logic ulla function create ath new feature old
browseril runn cheypikkan sahayikum ithaanu
polyfill

debouncing
debouncing ennu parayunnath multiple events
oru mich nadakaathe oru limit vech function
execute cheyyunnath aanu expl- multiple button
clicks etc

throttling
multiple events varumbo our specific time
intervalil function execute cheyyunath annu
throttling
Type Casting
Our data typine convert cheyyunna process annu
typecasting
2 type und
Implicit (Automatic data converstionn) type
coeration
Example-
let num = 10; // number
let str = "The number is ";

// Implicit type casting: num will be converted to


string
let result = str + num; // "The number is 10"
console.log(result);

Explicit(manual data converstion) type


convertion
Example-
let str = "123"; // string
let num = Number(str); // Explicit type casting
from string to number

console.log(num); // 123 (now it's a number)


console.log(typeof num); // "number"

Common Type Conversions in JavaScript:


String to Number:

Number() function can be used to convert a


string to a number.
let str = "42";
let num = Number(str); // num will be 42 (as a
number)
Number to String:

Use String() or toString() method to convert a


number to a string.
let num = 42;
let str = String(num); // str will be "42"
String to Boolean:

Use Boolean() to convert a string to a boolean


value.
let str = "Hello";
let bool = Boolean(str); // bool will be true (non-
empty string is truthy)
Number to Boolean:

Use Boolean() to convert a number to a boolean


value.
let num = 0;
let bool = Boolean(num); // bool will be false (0 is
falsy)
Boolean to String:

Use String() to convert a boolean to a string.


let bool = true;
let str = String(bool); // str will be "true"

Entry-controlled loop
For loop
While loop= condion wrong avunnath vare loop
work avum

Exit-controlled loop
Do-while loop
Athyam loop work ayi avasaanam mathram
condition check cheyyukayullu
Memoization
Memoization ennu parayunnath our optimisation
technique aanu multiple function calls varumbo
result cache store akum pinne function vilikumbo
aah result aanu return cheyya
Pure Function:
A pure function is a function that satisfies the
following conditions:

No Side Effects: It does not modify any external


state (like global variables or objects). It only
uses the data that is passed to it as input.
Deterministic: Given the same input, it always
returns the same output. It does not depend on
any external state or variables that could change.
Expl-
function add(a, b) {
return a + b; // Always returns the same result
for the same inputs
}
console.log(add(2, 3)); // Output: 5

Impure Function:
An impure function is a function that does not
satisfy one or both of the conditions of a pure
function. Specifically, impure functions may:

Have Side Effects: They may modify external


state, such as global variables, or perform
actions like logging, writing to a file, or updating
a database.
Depend on External State: The output of the
function might depend on values that are outside
of the function's scope (like global variables or
the current time).
Expl-
let counter = 0;
function incrementCounter() {
counter += 1; // Modifies external state
console.log(counter); // Side effect: printing to
the console
}
incrementCounter(); // Output: 1
incrementCounter(); // Output: 2

ASSEMPLY LANGUAGE
Assembly Language ennu parayunnathu oru low-
level programming language aanu, ithu machine
code (CPU instructions) um binary language um
near aanu. Assembly language direct aayi CPU-ile
hardware ne control cheyyan upayogikkunnu.
Ithu high-level languages (like C, Java, etc.) ennu
compared to more human-readable illa, pakshe
faster and efficient aanu.
BOXING
Boxing ennu parayunnathu:

 Primitive values (like string, number, boolean) object-


aayi convert cheyyunnathu boxing ennu parayunnu.
 For example, string enna value oru object-il wrap
cheyyum, athe pole number oru object-il wrap cheyyum.

Unboxing:
Boxing kazhinjathinu sesham, object back to
primitive value aayi unbox cheyyum.
Dynamic typic
Its is nammal our variable initialise or declare
cheyyumbo athinte data type paranju kodkanda
avishyam illa automatically manassilayilla

You might also like