Easy JavaScript Notes ?
Easy JavaScript Notes ?
NOTES
JAVASCRIPT (JS) IS A LIGHTWEIGHT,
INTERPRETED, OR JUST-IN-TIME
COMPILED PROGRAMMING
LANGUAGE . JAVASCRIPT IS A
PROTOTYPE-BASED, MULTI-
PARADIGM, SINGLE-THREADED,
DYNAMIC LANGUAGE, SUPPORTING
OBJECT-ORIENTED, IMPERATIVE,
AND DECLARATIVE (E.G.
FUNCTIONAL PROGRAMMING)
STYLES. READ MORE ABOUT
JAVASCRIPT.
DATA TYPE IN JS
Primitive Non -Primitive
there are six
primitive data type
undefined string
number BigInt
boolean symbol
LOOPS IN JAVASCRIPT
for loop
While loop
do while loop
for in
for of
for each
For in loop For of loop
The JavaScript for in The JavaScript for of
statement loops through statement loops through the
the properties of an Object: values of an iterable object.
A JavaScript function is a
block of code designed to
perform a particular task.
//function is defined
function myFunction(p1, p2) {
return p1 * p2;
}
Function expression
Create a function and pass it
into a variable
Anonoymous function
function() {
// Function Body
}
How JS work ?
ANY JS CODE IS WORKED IN THE FOLLWING WAYS .
1. CODE COMPILATION
2. CODE EXECUTION
DOM TREE
DOM METHODS
getElementById
Syntax: Const element = document.getElementById();
Return a refrence to the element by it's ID.
If the specified ID is not found then it will return null.
querySelector
Syntax: Const element = document.querySelector();
Return the first element with in the document that match
the specified group of selector , or null if no match is found .
To return all matches (not only the first), use the querySelectorAll()
instead.
Both querySelector() and querySelectorAll() throw a SYNTAX_ERR
exception if the selector(s) is invalid.
ADVANCED
JAVASCRIPT
Event Propogation
It determine in which order our element recieve the event or Event
propagation is a way to describe the “stack” of events that are fired in a
web browser.
Event Bubling
With Event Bubbling, the event is first captured and handled by the
innermost element and then propagated to outer elements.
Event Capturing
With Event Capturing, the event is first captured by the outermost
element and propagated to the inner elements.
Capturing is also called "trickling", which helps remember the propagation
order
Syntax: id.addEventListener('event', function,true)
EVENT PROPOGATION
Event propogation can be characterised
into 3 categories
Capture phase
Target phase
Going form the
window to the event
target phase It's the
target phase Bubble phase
var x; // Declare x
EXAMPLE-
x = 5; // Assign 5 to x
SYNTAX
setTimeout(function,milisecond)
EXAMPLE
console.log("script start");
const id = setTimeout(() => {
console.log("inside setTimeout");
}, 1000);
for (let i = 1; i < 100; i++) {
console.log("....");
}
console.log("settimeout id is ", id);
console.log("Script end");
ASYNCHRONOUS JAVACRIPT
SET INTERVAL
same as setimeout but repeat the function continuoesly
SYNTAX
setInterval(function,milisecond)
EXAMPLE
console.log("script start");
setInterval(() => {
console.log(total);
console.log(Math.random());
}, 500);
console.log("script end");
ASYNCHRONOUS JAVACRIPT
FUNCTON CURRYING
Currying is a technique of evaluating function with multilple
argument , into sequence of function with single argument.