ny actually JS was developed
execution within web browsers
Actually developed for
JS code is executed
by is engine
Every browser have their own JS engine to run
JS code
Chrome V8
Firefox Spider Monkey
MS Chakra
Safari JS code
What is Node Js
An open source and platform javascript
cross
runtime environment It is a popular tool To run
JS code out of browser Uses V8 engine Written
in Ctt
What is boiler plate code
to run JS
Ways
In web browsers
Using node js
Using live server with html
THERE IS NO FLOAT IN JS Only Integer
you declare something and do
When not
assign a value to it it will be as undefined
x null
console x
log typeof
0 p Object
Javascript is a
dynamic language
REFERENCE TYPES
There a three reference types
Objects
Arrays
Functions
collection of
Objects key value pairs
To access inside objects
let course
title HHLD
description projects
rating 5 y
console course title
log
oh og course it
Value types vs Reference Types
VALUE TYPE copied the value
O P
let n Keerti harsha
let
y x Keerti
n harsha
console
log x
console
log y
REFERENCE TYPES
copied the referen
let p name Kati 0
p
let q p Educosys
p.name educosys Educosys
console log p
console
log q
DAY 2 11Indices starts from zero
let courses uld Ild dsa
console courses 0
log
Both the length and type can be dynamic
let courses 1954703 1954704 true null
console
log typeof courses
Op OBJECT
FUNCTIONS
Why do we need functions
function createcourse coursename
console
log creating coursename
createcourse hed
createcourse Md
HOISTING
console log x Undefined
Var n 10
console 10
log x
EXECUTION CONTEXT
GLOBAL EXECUTION CONTEXT
Every time a JS code is run a new
execution content will be created and added
to the call stack
Execution content have two main components phases
1 Before running the code memory is allocated to
the variables and functions MEMORY PHASE
2 Code is executed line by line CODE PHASE
JS is a
synchronous single threaded language
ININDOIN AND THIS
Console
log a 1 undefined
log this a 11 undefined
console
console
log window a 11 undefined
var a 10
console 11 10
log a
log this a 11 10
console
console
log window a 1 10
console window
log
console Log this window 11 true
LET CONST VAR
3 ways to declare variables
Let const var
strict initialized with
undefined
Let Not hoisted var Hoisted
proof
soped Const Not hoisted scoped
fun on
Temporal Dead Zone
The time between the initialization
and declaration of let and const is called
as temporal dead zone
console
log a 11 Reference Error
console
log b 11 Reference Error
let a 10
const b 20
Block scoped vs Function scoped
var a 10
let b 10
const c 20
console 11 10
log a
console
log b 1 b is not defined
console C 11 C is not defined
log
Global content vs Local content
function hello 1 2 The function is gone
let n 10 after running context
console whereas
log x n
stays
hello 11 because it is
global
let x 100 context
What is lexical scope
We check where it is located and can
we access it or not
Functions are called first class citizens
Functions can be assigned to
actually
variables and can also be passed as
arguments
to different functions and can even be stored
in data structures
function add a b 11 bilobal content
return a b
console add
log
console add 2 3
log
let sun function a b 11 Script
return tb y Localent
a
console
log sum
console
log sum 2 3
How functions can be passed as arguments to another function
let sum function a b
return a b
let diff function a b
return a b
function operate operation a b
return operation a b
console
log operate sum 2 3
console
log operate diff 3,2
pHIGHER ORDER FUNCTIONS It is a function that takes one
or more functions as arguments or returns a function as
its result
ARION Ections
Multi line return statement
let sum a b
let c a b
return c y
Single line return statement
let sum a b a tb
Nested Functions Function LexicalScope closure
let a 100
function outer 11 innerc
I a 10
function inner 11 console
log hello
console hello
log
return inner 3 11 hello
let returnedfunc outer 11 1 20
a 20
console log returnedfunc
returnedfunc
Counter
function outer 11 I
let count 0 2
function inner 1 3
1 I
console count
log
return inner y
let incrementcounter outer is
incrementcounterL
incrementcounterL
incrementcounterL
incrementcounterL
When have
we use
many closures we over
consumption of memory and we will end up having
memory leaky and we have to handle them So
use closures when actually needed