[Go to site: main page, start]

0% found this document useful (0 votes)
16 views13 pages

Java Script Raam Notes

The document provides an overview of JavaScript, including its characteristics, execution context, and how to run JavaScript both inside and outside a browser. It covers key concepts such as variables, data types, and methods for manipulating strings and arrays. Additionally, it explains the syntax for embedding JavaScript in HTML and the use of various operators and functions.

Uploaded by

Saurya Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views13 pages

Java Script Raam Notes

The document provides an overview of JavaScript, including its characteristics, execution context, and how to run JavaScript both inside and outside a browser. It covers key concepts such as variables, data types, and methods for manipulating strings and arrays. Additionally, it explains the syntax for embedding JavaScript in HTML and the use of various operators and functions.

Uploaded by

Saurya Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Script

NOTE:-
J S is H.L.L(one can easily read)
Browser :- It is an application which provides environment to run J.S
instructions from H.L.L to M.L.L.
-JS code can run both inside and outside the browser . Inside Browser – JS
Engine.
Outside browser – node-JS Engine
-NODE : It is the combination of C++ and V8 engine(Chrome JS Engine) with
bundles of methods and rules.
NODE provides environment to run js outside the browser. This invention help
the js to gain its popularity in usage as a backend language.
We can run JS both inside AND outside the browser.
CHARACTERISTICS OF JAVA SCRIPT
1: Purely object oriented
2: purely interpreted
3: Synchronous (coz , it follows single threaded architecture which has only
one STACK)
4: Scripting Language
5: Programming Language
NOTE:-
OBJECT :- IT is a block of memory which has states(variables) and
behaviours(functions).
-[Link](arguments); here , console is an object , dot is a period or access
operator and log is a function and member of console that accepts arguments
as data to print in console.

TO EXECUTE JS ON BROWSER
1We CAN EXECUTES JS instructions directly in console provided by the
browser.
2: We can executes Js instructions by embedding it in HTML page.
Types:-
a. INTERNAL
b. EXTERNALS
1 Internals :- With the help of script tag , we can embed js instructions.

SYNTAX:
html code….
<script>

Js code……
</script>
Html code……
2EXTERNAL
1:- WE can create a separate file for JS with a extension .js .
2 Link the JS file with html page using src attribute of script tag.
SYNTAX :-
HTML CODE ……
<script src = “ path/file_name .js”> (If js file and html file is in the same folder
path is not required )

Js code …….
</script>
HTML CODE …….
TOKENS :- Smallest unit of any programming language. And consists of
1KEYWORDS :- A predefined reserved word which understandable by the js
engine is known as keyword.
NOTE :- Every keyword must be in the lower case and it is not used as
identifiers. Ex:- if , for , while ,do-while ,null , switch.
2 IDENTIFIERS :- Name given by the programmers to the components of JS like
variables , functions, class etc. are known as identifiers.
Rules for identifiers
1 An identifiers can not start with number.
2 except $ and _ no other special characters are allowed in .
3 We can not use keywords as an identifiers.

3 LITERLAS /Values : Data which is used in the JS program is called as literals


/values.
TYPES OF VALUES IN JS:
1 NUMBERS
2 STRING
3 BOOLEAN
4 NULL
5 UNDEFINED
6 OBJECT(NON-PRIMITIVE)
Bigint

NOTE :-
-Numbers between the range ( -(2^53 - 1) to (2^53-1)) are treated as number
type.
-We can use Bigint type to store numbers beyond the given range by suffixing
the number with ‘n’.
Exe. :- 1 ---- number type
1n ----- Bigint type
declare Initialize Redeclare Reinitialize
var Yes Yes Yes Yes
let Yes Yes NO Yes
const Declaration NO NO
and
initialization
at same time

GLOBAL EXECUTION CONTEXT


1 Variable Phase
2 Execution Phase
Exe. [Link](“Hello”)
[Link](a)
Var a= 10 (hoisting)
. [Link](a)
Var b=10
. [Link](b)
. [Link](a)

VARIABLES :-
A name block of memory which is used to store a value is known as
variables(container to store data).
NOTE :- In JS variables are not strictly typed , it is dynamically typed . Therefor
it is not necessary to specify type of data during variables declarations.
-In a variable we can store any type of value.
-SYNTAX : var/let/const identifiers;
Exe.
Var a; //declaration
A =10; //initialization
[Link](a);

let b;
b =20;
[Link](b);

const c = 30;
. [Link](c);
NOTE :-
When a variable is declared in JS , Js engine implicitly assigns undefined value
to it.
Exe
Var a ;
Console,log(a) //undefined

UNDERSTANDING EXECUTION IN JS:


1 Everytime when js engine runs a js code , it will 1st create a ‘global execution
context’
2 The global execution context has 2 parts
A Variable area
B Executional area
3 JS engine generally use 2 phases to execute a JS code
Phase 1 ALL the memory is allocated for the declaration in top to bottom order
and assigned with the default value “undefined” in variable area of global
execution context.
Phase 2 All the instructions get executed in the top to bottom order in
execution area of global execution context.

Exe. :- Trace the following code


Clg(a)
Clg(b)
Var a;
A = 10;
Clg(a)
Var b =20;
Clg(b);

TRACING OF ABOVE CODE


1 Creation of global execution of context
2 In the variable area, only variable declaration are stored
3 for clg(a) ; //undefined ,because by default for var a , it is undefined .
Similarly for clg(b)
4 For clg(a); //10 ,coz ,the default value of “undefined” is replaced by 10.
Similarly for clg(b) . It happens in the execution /functional area.
5 So , the Js interpreter scans the JS code 2 times . Once for variable area and
another one for executional area.
HOISTING :- JS allows a programmer to use a member (variable) before the
declaration statement . This characteristic is known as hoisting.

STRINGS :-
In Js strings can be represented using single quote , double quote or backticks.
Note :-
- The start and end of a string must be done with the help of same
quotes.
- If a text contains single quote then it can be represented using double
quotes.
Text : I am a doctor
In JS : “I am a doctor”

BACKTICKS :- A backticks can be multiline string.


Ex.
Var hobbies = `My hobbies are
1. Cricket
2. Movies
3. Stock`;
[Link](hobbies);
Note:- -
- The strings represented by using backticks is also known as template
string. The advantage of it is we can substitute and express it using ${}.
Q : What are the advantages of using backticks to represent a string over single
and double quote ?
Ans :-
Plus (+) operator :
+ operator behaves like a concat operator , if the operands are string.
+ operator behaves like a addition operator if it operands are number.

Exe.1
let first_name = prompt("Enter your first name")
// let second_name = prompt("Enter your last name")
// [Link](`The name is ${first_name} $
{second_name}`)

Exe.2

let num1 = Number(prompt("first number"))


let num2 = Number(prompt("second number"))
[Link](num1+num2);

TYPEOF OPERATOR
1 It is a keyword used as an unary(checks only one data/value) operator to
identify the type of data.
2 SYNTAX:-
typeof value
Exe.
[Link](typeof 1); //number
[Link](typeof 1n); //bigint
[Link](typeof ‘1’); //string
[Link](typeof “1”) ); //string
[Link](typeof `1`)); //string
[Link](typeof true); // Boolean
[Link](typeof false); // Boolean
[Link](typeof False) ; // error.(‘f’ should be in lower case)
[Link](typeof undefined); //undefined
[Link](typeof null); // object

Split() :
It is method where we will be using it convert the string to array
Eg: let a = “abc”
let b = [Link](“”)
[Link](b):
Output [“a”,”b”,”c”]
Reverse()
It is a method which reverse all the element inside an array
Let a = [“a”,”b”,”c”]
let b = [Link]()
[Link](b)

Output
[“c” ,”b”,”a”]

Join() :- It ia s method used to join all the array elements


It is used to convert array to string

Let b = [“c”,”b”,”a”]
let c = [Link]("")
[Link](c)
Output :- cba
toUpperCase() :- This method is used to convert all the characters
into uppercase or capital letter.
let a = “ashutosh”
let b = [Link]()
[Link](b);
Output :- ASHUTOSH
toLowerCase() :- This method is used to convert all the characters
into lowercase or small letter.
let a = “ASHUTOSH”
let b = [Link]()
[Link](b)
Output :- Ashutosh

ARRAYS :- It is a collection of heterogenous (different data type


elements
-you can add any data types in JS array. )
-Representation of array in JS is []
Exe :- let arr = [12,”hi”,2.7,”h”,67,45,32,89,true,undefined,null,{}]
In the above example inside arr variable we have store all the data types , It
supports all the data types
Array methods:
1 pop() :-
It is a method which is used to delete the last element of an array.
Exe. :- let arr = [1,”hi”,23,45,66]
[Link]()
[Link](arr);
Output :- [1,”hi”,23,45] last element 66 has been deleted

2 push() :-
It is a method which is used to add the element at last index.
Exe. :- let arr = [1,”hi”,23,45,66]
[Link](20)
[Link](arr);
Output :- = [1,”hi”,23,45,66,20]

3 shift() :-
It is a method which is used to delete the first element of an array.
Exe. :- let arr = [1,”hi”,23,45,66]
[Link]()
[Link](arr);
Output :- = [”hi”,23,45,66,20] first element 1 has been deleted.
4 unshift() :- It is a method which is used to add the element at first index.
Exe. :- let arr = [1,”hi”,23,45,66]
[Link](20)
[Link](arr);
Output :- = [20,”hi”,23,45,66,20] 20 has been added at the first index.
5 splice() :-
It is a method used to add and delete the element at the same time
-splice method affect original array
- It will accept three arguments
SYNTAX :- splice(start index , how many elements to be deleted ,which
element to be added )
Exe. :- let arr = [1,”hi”,23,45,66]
[Link](1,2,100)
[Link](arr);
Output :- = [20,100,45,66,20]
6 slice() :- It is a method which is used to delete the element at the same
time take out sliced element from the original array.
- It will not affect the original array.
- It will accept two arguments
- End index will be always ignored
SYNTAX
Slice(start index , end index)
Exe. :- let arr = [1,”hi”,23,45,66]
Let b = [Link](1 , 3)
[Link](b);
Output :- [1,45,66]

7 includes() :- It is a method used to check whether the element present


In array or not.
- Includes will always return “Boolean type” value.
SYNTAX :- [Link](element which you wanted to check)
Exe.

let a = [10,20,30,40]
let e = [Link](50) //false(50 is not present in
a)
[Link](e);
let f = [Link](40) //true(40 is present in a)
[Link](f);

8 indexof() :- It is used to check the index value of particular element


- Indexof() of will return index value of an element
SYNTAX :- [Link](element which you wanted to know the index value)

let a = [10,20,30,40]
let f = [Link](30)
[Link](f) // 2 index value of 30

9 concat() :- This method is used to merge multiple array into one single array
Syntax :- [Link](array to be merged with a)
Exe.

let a = [10,20,30,40]
let b = [50,60,70,80]
let c = ["a","b","c","d","e"]

let d= [Link](b,c)
[Link](d);
Output :- [10,20,30,40, 50,60,70,80,
["a","b","c","d","e"]]

10 sort() :- This method is used to sort the element of an array in ascending


order.
Syntax :- [Link]()
Exe.

let unsort = [98,87,34,532,1,34]


let sorted = [Link]()
[Link](sorted)

let unsortstr = ["s","g","q","c","l"]


let sortstr = [Link]()
[Link](sortstr)
Output :-
[1, 34, 34, 532, 87, 98]
['c', 'g', 'l', 'q', 's']

You might also like