Java Script Road Map
Java Script Road Map
road map
Basic
• Variables in JS • Objects
• Loops • Events
• Prototyping
• Call backs
• IIFE
Topics to • Promises
learn
• Ajax
• Async Await
• Closures
• OPPs Concepts
• JSON
Variables in
Java script
What is variable
How to declare variable
Variables
in js Rules to name a variable
How to create variable :
• var
• let
• const
Variables
in js
Rules for variable names:
• Number • Undefined
• String • Null
• Boolean
Data types
in Js Composite
• Array
• Object
Operators in
Java script
Arithmetic Operators Type Operators
• Add 2+4→6
• Subtract 2 - 4 → -2
• Modulus 5 % 2 → 1
• Negate -(5) → -5
Comparision Operators
Ex:
if ( x != 0 )
Operators result = y / x;
in Js else
result = “not defined”;
Logical Operators
= x=y x=y
+= x += y x=x+y
-= x -= y x=x-y
*= x *= y x=x*y
/= x /= y x=x/y
Operators %= x %= y x=x%y
in Js <<= x <<= y x = x << y
>>= x >>= y x = x >> y
>>>= x >>>= y x = x >>> y
&= x &= y x=x&y
^= x ^= y x=x^y
|= x |= y x=x|y
**= x **= y x = x ** y
Bitwise Operators
4. Switch statement
Syntax of if statement
if(condition){
statement 1
statement 2
Conditional statements .
in Js .
.
statement n
}
Syntax of if –else statement
if(condition){
statement 1
statement 2
.
.
.
statement n
Conditional statements
}
in Js
else{
statement 1
statement 2
.
.
.
statement n
}
Syntax of if-else-if statement :
if(condition 1 is true) {
// code is executed
else {
// code is executed
}
Syntax of switch statement
switch (expression) {
case choice1:
run this code
break;
Conditional statements
case choice2:
in Js run this code instead
break;
default:
no case matches run this code
}
Loops
in
Java script
Why loops(iterative statements) are needed:
while loop
do-while -loop
Loops
in Js
for-in-loop
for-of-loop
Syntax of for loop :
// Code to be executed
Loops }
in Js
Syntax of -while loop :
do {
// Code to be executed
}
Loops
in Js while(condition);
Syntax of do-while loop :
while(condition) {
// Code to be executed
Loops
in Js }
for in vs for of
loops in
Java script
Functions
in
Java script
Topics:
• What is function
• Why functions
What is Block:
Anything that enclosed between { }
Functions Ex: {
in JS statement 1 ;
statement 2 ;
statement n ;
}
How to create function/Function definition:
function functionName(parameter1,parameter2 …parameter n) {
body
return value;
return result;
}
How to call functions:
functionName(parameters)
Ex: sum(7,8)
Functions
in JS
What is function expression:
Assigning function to a variable
Ex:
add = function sum(num1,num2) {
add(7,8) => 15
sum(7,8) => Error
Types of Functions
in
Java script
Types:
• Named functions
• Anonymous function
body
return value;
Functions
in JS Ex: function sum(num1,num2) {
return result;
}
Anonymous function:
function (parameter1,parameter2 …parameter n) {
body
return value;
return result;
return result;
Functions }
in JS
IIFE:
When we want to execute a function immediately where they
Created,IIFE used.
) ( 6,8 );
Arrow function:
body
return value;
Calling: product(5,8)
Arrow function forms :
Calling: cube(5)
Arrow function forms :
3. If no argument
Function definition:
function product(num1,num2) {
product(8) -> ?
Default parameters:
function product(num1,num2=1) {
return result;
}
Functions
in JS Sum(8) -> 8
Sum(8,7) -> 56
Sum(8,7,9) -> 56
Rest parameters:
We can make function to accept unspecified number of parameters
Rest parameter
function product(num1=1,num2=1, …arr) {
return result;
Functions }
in JS
result = result*num
Functions
in JS }
return result;
}
forEach in
Java script
For every element present inside array the specified function
will be executed.
Syntax :
arr.forEach (function funName(currentItem,index,arr)) {
//code here
});
forEach
in JS
currentItem :Required
Index : optional
arr : optional
For every element present inside array the specified function
will be executed.
arr.forEach (test);
in JS code
}
Objects in
Java script
Object:
• object is collection of elements in the form of properties and
methods.
• Property is a key-value pair.
name: “RRR"
}
How to access object values :
We can access values by using keys in 2 ways
movie[name] ->Invalid
Objects
in JS 2. obj.key
Ex: movie.name
How to add new properties to object:
We can add properties by using keys in 2 ways
1. obj["key"] = value
Create object
2. obj.key = value
in JS
1. obj["key"] = value
Create object
2. obj.key = value
in JS
}
Create object
in JS Step2: create object with constructor function call :
Create object },
in JS Music: {
value: “Keeravani”
}
})
Console Methods
in
Java script
• console.log() • console.count()
• console.info() • console.countreset()
• console.warn() • console.time()
• console.clear() • console.group()
• console.assert() • console.groupend()
DOM
in
Java script
What is DOM
• Methods
2. document.getElementsByClassName(“classname”)
Returns list of all elements belongs to the specified class
3. document.getElementsByTagName(“tagname”)
Returns list of all elements with the specified tag
4. document.querySelector(“.class/#id/tagname”)
Returns the first object matching CSS style selector
5. document.querySelectorAll(“.class/#id/tagname”) )
Returns all objects Matches the CSS Style Selector
DOM properties to select HTML Elements :
• document.body
• document.head
• document.title
• document.anchors
• document.forms
• document.images
• document.scripts
DOM Manipulation
in
Java script
<html >
<head>
<title>My HTML Document</title>
</head>
<body>
<h1>Heading</h1>
<div id="div1">
<p>P Tag 1</p>
</div>
<div id="div1">
<p class="p2">P Tag 2</p>
</div>
</body>
</html>
Topics :
CSS Styling
• How to set/change attribute of an element
in JS
Modal Windows in
Java script
3 modal windows :
Modal windows
Java script • Confirm – to get confirmation from user
Events
& Event handling in
Java script
Topics :
Events
& Event handling in • Ways to handle events in JS
Java script
Event
• Event is nothing but an action
submit
reset
change
Ways to handle events:
function first(fun){
Higher order
fun()
functions in
Java script }
function second(){
console.log("This is second function")
}
first(second)
Example of returning a function:
function first(){
return second
function second(){
Higher order console.log("This is second function")
functions in }
Java script
let res = first()
res()
This keyword
in
Java script
Value of this keyword outside a function /object
• ceil()
• Sign()
• floor()
• abs()
• trunc()
• sqrt()
• random()
• pow()
Math Object • exp()
• max()
• log()
• min()
• log2()
• round()
• log10()
String Methods in
Java script
Window Object in
Java script
properties of Window Object
• document
• innerWidth
• outerWidth
• innerHeigth
• location
• closed
• Name
• navigator
Open() & close()
browser window
with sJava script
Methods of Window Object
• Open()
• Close()
• moveBy()
• moveT0()
• alert()
Window Object • Prompt()
• confirm()
• reSizeTo()
• reSizeBy()
• print()
open() Method syntax:
• scrollable
moveTo() & moveBy()
resize()
browser window
with Java script
• moveTo()
• moveBy()
• reSizeBy()
Asynchronous
Java script
AJAX
• AJAX – Asynchronous JavaScript And XML
• Data loaded by AJAX call is done asynchronously with out page refresh
AJAX • Web server will send response which contains data that we have requested
AJAX Response
Load
• In JavaScript we have to use XMLHttpRequest object to make AJAX call
AJAX Response
Load
Method Description
new XMLHttpRequest() Creates a new XMLHttpRequest object
open(method, url, async, user, psw) Specifies the request
onprogress triggers periodically while the response is being downloaded, reports how much
has been downloaded.
Promise
• This object returns some data either success data or error
information.
})
• States of promise
Pending
fulfilled
rejected
Promise
Fetch API
In JavaScript
• fetch() is a method of browser window Object which helps to make AJAX call
promise.then(function(response){
console.log(response)
})
Prototype & _ _proto_ _
In JavaScript
function movie(name,director){
this.moviename=name
this.director = director
this.getGetails = function(){
console.log("Director of ",this.moviename,":",this.director)
}
}
Prototype
pushpa RRR
Sukumar RajaMouli
getDetails() getDetails()
pattern
Syntax : /pattern/[flags]
Regular
Ex: /hello/
Expressions
/^[0-9]{10}$/
2. Using RegExp Constructor function
new RegExp(“^[0-9]{10}$”)
Regular Expressions
In JavaScript
• Regular expression is a sequence of characters, helps to create a search
pattern
Syntax : /pattern/[flags]
Regular
Ex: /hello/
Expressions
/^[0-9]{10}$/
2. Using RegExp Constructor function
new RegExp(“^[0-9]{10}$”)
Brackets:
[^……] Any one character not between [a89] => everything except a , 8 and 9
the brackets
[0-9] Any number from 0 -9 0 /1/2 …./9
* Match zero or more times. Bm* => "B", "Bm", "Bmm", "Bmmm", and so on…
? Match zero or one time. bS? => “b" or “bs", but not “bss” ….
console.log(movies.split(' '))
separated by separator
let movies = ['RRR', 'BhemlaNayak', 'Pushpa', 'Sarainodu'];
console.log(movies.join('-'))
Output: "RRR-BhemlaNayak-Pushpa-Sarainodu"
Syntax: array.join(separator)
console.log(movies.join())
Output: "RRR,BhemlaNayak,Pushpa,Sarainodu"
Multi dimensional
Arrays
In JavaScript
let product = [1,"Samsung Galaxy A53",30000]
Multi 0 1 2
dimensional
array
let products = [
[1,"Samsung Galaxy A53",30000],
[2,"Vivo Y75",20000],
[1,"Redmi 10 prime",13000],
]
let products = [
[1,"Samsung Galaxy A53",30000],
[2,"Vivo Y75",20000],
[1,"Redmi 10 prime",13000],
]
0 1 2 0 1 2 0 1 2
1 Samsung Galaxy A53 30000 1 Vivo Y75 30000 1 Redmi 10 Prime 30000
0 1 2
let products = [
[1,"Samsung Galaxy A53",30000],
[2,"Vivo Y75",20000],
[1,"Redmi 10 prime",13000],
]
0 1 2 0 1 2 0 1 2
1 Samsung Galaxy A53 30000 1 Vivo Y75 30000 1 Redmi 10 Prime 30000
0 1 2
products[0] =[1,"Samsung Galaxy A53",30000]
products[0][0] = 1
products[0][1] = Samsung Galaxy A53
products[0][2] = 30000