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

jsbackend[1]

Javascript

Uploaded by

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

jsbackend[1]

Javascript

Uploaded by

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

------------Module 2-------------

javascript
----------

- javascript can be used in both frontend and backend


- frontend - behaviour to a web application
- backend - logical operations
- browser understanding language - js,html,css
- node js - environment to run js outside the browser
- single thread programming language - line by line execution
- dynamically typed language
- both procedural and oops paradigms are support

run file
---------
node filename.js

Display a content
-----------------
console.log(content)

Datatype
--------

primitive Datatype - basic datatype


1)string - value should be inside single quote or double quote
2)number
3)boolean : true or false
4)undefined : variable which is declared but not assigned a value
5)null : intentional absense of value
6)BigInt : large numbers eg:2^56
7)Symbols : reprsent a unique identity

Non-primitive Datatype - combination of primitive datatype


8)object
{key:value}

variables
---------
- used to store single data at a time

-rules to create variables - identifiers


1) can start with letters(a-z,A-Z), dollar symbol($) , underscore(_),
Prefer(letter)
2)variable name should not start with digit but the subsequent character
can be a digit

eg:x1

3) If there is more than 1 word in a variable name


-they can be seperated by underscore or
-the subsequent words should start with capital letter(camel case)

-there should not be space between the variable names


eg:car name

synatx - declare a variable


-------
1) variable name = value

typeof - predefined function

2) keyword variablename = value

keyword
--------
- keywords are a set of reserved words which provide special meaning to a
variable
- these keywords cannot be used for any other purpose

const- no reassigning possible , hoisting is not possible


let- reassigning is possible , hoisting is not possible , block level
scope
var - reassigning is possible , hoisting is possible

variable hoisting
-----------------

defining a variable before it is declared

concatenation
-------------

addition of different datatype

string+number=string
number+number=number
string+string=string

Template Literals
-----------------
-way of displaying contents
synatx
------
content ${variablename}

operators
---------

1)assignment operator(=)
2)Arithmetc operator
addition(+)
substraction(-)
multiplication(*)
division(/)
exponential()
remainder(%)

3)Relational operators
-returns boolean value
<
<=
>
>=
== - double equal to - check value only
=== - triple equal to - check both value as well as datatype
!=

4)logical operator
-return boolean value
-can be used between relational operators

AND(&&)
T && T =T
T && F =F
F&&T=F
F&&F=f

OR(||)
T || T = T
T || F = T
F || T = T
F || F = F
NOT (!)
!T=F
!F=T

5)Increment(++)/decrement(--)

6)shorthand
x=x+10 -- x+=10
x=x-10 -- x-=10
7)ternary operator

condition?true:false
8)truthy operator
condition && true

conditional statements / decision making statements


---------------------------------------------------
if else statement

synatx
------
if (condition){
statement
}
else{
statement
}

looping statement
-----------------
-to do task repeated at a particular position

-while looping

synatx

variable initialization
while(condition){
statement / task
loop exit condition / inc /dec operators
}

-come out of the loop - only when the condition become false

/even number - number%2=0

to convert str to num use "Number"

math.floor is used to remove decimal point

-for loop
---------

for(variable initialization,condition,inc/dec){
statement
}

break statement - inorder to forcefully exit a loop

nested loop - loop inside another loop


-pattern

Function
--------

-To do task repeatedly at different locations of the programming file


-It helps to reduce the number of codes in the programming file
-two parts
1) Function defenition
- where the task is defined
- syntax
--------
function functionname(arg1,..... argn){
statement/task
}

2) Function call
-inorder to execute the task
- syntax
functionname(arg1,....argn)

Arguments : Values outside the function


-optional

- variables inside a function is having functional scope - it cannot be


accessed outside the function
- inorder to access the variable outside the function we need to use
return statement
- statement after the return statement will not execute hence return
statement should be places as the last statement of the function

Arrow functions
---------------
-ES6 - Arrow function is Prefered

function defenition
-------------------

const variablename = ()=>{statement}

function call
variablename()
functional hoisting
-------------------
- function call before function defenition
- regular function - hoisting is possible
- arrow function - hoisting is not possible

category of functions
---------------------
-1) predefined functions / builtin function
- eg : console.log , math.floor , eval , typeof , e.t.c . . . . . .
. . .
-2) call back function
- a function calling another function

-3) nested function


- a function defe inside another function
- closure property - parent property can be accessed inside child
property , but child property cannot be accessed inside parent property
-4) synchronous function
- function which does not have any time delay
-5) Asynchronous function
- function with time delay
- eg: setTimeout() , api call

Data Structure
---------------

A specialised format for organising , processing , retrieving and


storing data

eg: stack , queue , linked list , list and array

Array
-----
- unlike variables array is a single variable can store more than one
data of different datatype ,
where each items in array is seperated by commas and enclosed within
a square bracket

variablename = [item1,item ....itemn]

- key:value
- index position - start 0 end (length-1)
- value - item
- length - total number of items in an array (total number of memory
locations)
- array in js is infinite (does not need to specify the length of an
array)
Array operations
----------------
1) push() - to add items to an array as the last element
2) unshift() - elements to insert at the start of the array
3) pop() - to remove an item from the end of an array
4) shift() - to remove the first item from the array
5) sort() - to arrange elements in an array in ascending or
descending order
6) flat(depth) - used to change the dimension of an array
- infinity - directly changes to one dimension
7) forEach() - used to access each items from a given array(for
loop)
8) map() - it access each items from the given array and returns a
new array having the same numbers elements
9) reduce() - it returns a single value from the given array
eg: sum,highest,lowest,average
10) filter() - create a new array with elements satisfying a
particular condition
11) some() - returns boolean value based on condition
12) find() - it returns the first item satisfying the condition
13) includes() - it returns boolean value based on items in array
14) indexOf(item) - return index value of the item
15) lastIndexOf() - return the last index of the item
16) splice(startindex , deletecount , additem) - to add and remove
items at any point in a given array
17) slice(startindex , endindex) - it returns selected number of
items from a given array - end index will be excluded - new array
- negative value
18)reduceRight()

different ways to access array items


-----------------------------------

1)regular for loop


2)in method - return index value of an array
3)of method - returns directly the values of an array

linear approach
---------------

- checks / compare each elements of an array


- time consuming
- small arrays
- can be applied in any type of array

Binary approach
---------------

- will not checks / compare each elements of an array


- it is not time consuming compared to linear approach
- used in large dataset/array
- can be used only in sorted array(arranged in ascending order)

Algorithm
---------
step by step procedure to solve a problem

nested array
------------
array inside another array

string
------

string : sequence of characters stored in different memory location


-immutable(not changable)

string methods
-------------

1)toUpperCase() - to convert into capital letter


2)toLowerCase() - to convert into small letters
3)startsWith() - check whether a given string starts with a
particular characters
- returns boolean value , case sensitive
4)endsWith() - check whether a given string ends with a
particular characters
- returns boolean value , case sensitive
5)subString() - to check a new string from the given string -
end index is excluded - no negative values

6)slice() - to check a new string from the given string -


end index is excluded - negative values
7)trim() - remove space at the ends in a string
8)split(seperator) - split the given string based on a seperator
- returns new array having the elements
9)Array.from() - return a new array with individual characters
as the element
10)replace(searchvalue,replacevalue) - replaces the first matching
character
11)replaceAll() - to replace all the matching characters

Object
------

- unlike array it can store more than 1 data with higher clarity

-defenition :
Object is a single variable which can store more than one data of
different datatype as
key:value pair that are seperated by commas and enclosed within curly
bracket

syntax
------
variablename = value
variablename = [value1,va........valn]
variablename = {
key1:value1
key2:value2,....
keyn:valuen
}

get data
- objectname['key']
- objectname.key - exact key
- in

add data
- objectname[key]=value

update data
- objectname[key] = value

delete data
- delete objectname.key

object oriented programming


---------------------------

-its a modern paradigms(style) which consider real time entity into


object and class
-here both data(property) and function(method) are considered as a
single entity

inheritance
-----------
- used to access properties and method of one class to anthor class
- increases reusability
- keyword - extends
-parent class - from where the properties and methods are accessed
- super class / base class
- child class - the class which access the properties and method
- sub class / derived class

object inheritance
------------------
keyword- _proto_
multilevel inheritance - access methods and properties indirectly from
parent class

polymorphism
-------------
poly - many
morphism - forms

- method overloading
---------------------

-method with same name but different arguments


-it executes based on the number of argument
- javascript does not support method overloading
- spread operators (...) -

-method overriding
-------------------

-method with same name and same number of argument


-execute the last written method
-js support this concept

Exception Handling
----------------------
Exception : run time error

try-catch block
synatx
------
try{
statement -whose statement which might commit error
}
catch{
statement to resolve the error
}
finally{
-statements which need to be execute in both cases
-optional block}

You might also like