jsbackend[1]
jsbackend[1]
javascript
----------
run file
---------
node filename.js
Display a content
-----------------
console.log(content)
Datatype
--------
variables
---------
- used to store single data at a time
eg:x1
keyword
--------
- keywords are a set of reserved words which provide special meaning to a
variable
- these keywords cannot be used for any other purpose
variable hoisting
-----------------
concatenation
-------------
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
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
-for loop
---------
for(variable initialization,condition,inc/dec){
statement
}
Function
--------
2) Function call
-inorder to execute the task
- syntax
functionname(arg1,....argn)
Arrow functions
---------------
-ES6 - Arrow function is Prefered
function defenition
-------------------
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
Data Structure
---------------
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
- 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()
linear approach
---------------
Binary approach
---------------
Algorithm
---------
step by step procedure to solve a problem
nested array
------------
array inside another array
string
------
string methods
-------------
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
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 overriding
-------------------
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}