Javascriptt
Javascriptt
Variable declaration
var fname=”pratik”;
Datatypes
String
Number
Array
Object
Typeof
Boolean
Undefined
Arithmetic Operators
=,+,-,*,**(power),/,%(remainder)
+ act as both concate and add
- act as only subtract
Comparison operators
= justify left right values, == only sees the value same or not, === checks value same or not and also cheks the datatype
< , > , <= , >= (do not check datatype); != not equal to,!==(checks datatype)
Logic Operators
&&- And Operator requires both condn true to show true
|| - OR Operator require only one condn true to display true
!== - NOT operator require same value to show opposite O/P
Ternary Operator
All loop is written in one line
Loops
Three types of loops for, do while, while.
For loop- written in one line first initializing then giving condition and after increment or decrement
While loop- it firstly checks the condition true or not then only execute
Do while – it first print compulsory one value then after checks the condition
Switch statement- it’s used for multiple cases or condition it is easy to write
Pop Ups
Alert- used to show the popup message only
Prompt- used to accept value from user in the form of popup
Confirm- used to show alert after the delete or confirm option
Break statement:- it breaks a specific series till it after not print anything
Continue statement:- it breaks a series but it does not print that specific element after wards it prints the whole series
Array written always as array name=[array elements], elements in array can be accessed as (arr name[element no.])
Array methods
pop()-removes element of array from end, shift()-removes from start
push()-insert element from end, unshift()- insert element from start
Splice()method- it do not create new array it changes in itself only. It has three parameters 1st is which posn u wanna select,
2nd how many element u wanna remove, 3rd is how many elements u wanna insert before the mentioned posn in 1st
parameter.
Slice()method- it creates new array from the main array after modifying. Has two parameters 1st where to start from, 2nd
where to end (it do not take end value it takes prior to it posns value). It removes front and back value to the mentioned
posns.
return is statement which can specify the value to the returned to the caller.
Any variable declared inside the function is called local variable. Which can be accessed only in the function.
Any variable declared outside the function is called global variable. Which can be accessed anywhere.
Anonymous function- function with no name, used in if we want write function in function. let a= function(){…..}
Arrow function- function with no name, and no function keyword e.g.- let a= ()=>{ …. }
setTimeout method- two parameters passed - function and the timing seconds. Seconds used to display the output of
function after specific mentioned time.
setInterval method- same as setTimeout but output comes delaying after and after continuously.
Object- defined in curly braces {}, used to store multiple data with multiple datatypes. We store data in it in form of Key and
values. Object can be created in two ways We access it by . notation.
Arrays, Functions & object in object can be written in object.
ForEach() method two parameters passed first for values and elements and second
For 0f() method iterates the array and object values
(for of cant be used for object values iteration we have to write Object.values(object name)
For in() method iterates the array and object values and index value (key also of object)
Math is object to perform various methods.
Hoisting:-
Its moves the declaration of variable in JavaScript before the initialization or printing. Only for var not for let,const
DOM- the document object model is an application program interface(API) for manipulating HTML document.
Various operations performed add, remove & modify.to modify parts of the document.
document.getElementById(“”)-Takes element or tag by id selector specified by the particular tag
document.getElementByClassName(“”)- takes tag by specified class selector and converts them to array bcz class selector is
used for taking bulk tags at one time.
So for iterating values for loop is taken
String methods
Let str=”This is javascript
.length- Finds the length of a string with including blank spaces
.toUpperCase()- covert all string to uppercase
.toLowerCase()- convert string to lowercase
.startsWith(“”)- checks the given word is starting of string or not return bolean
.endsWith(“”)- checks the given word is the ending of string or not return boolean
.includes(“java”)-checks the word is present in whole string or not (accepts half word also) returns boolean value
.search(“”)- checks the word and returns the position of word starts with 1 and if word not there return -1
.match(/is/g)- checks how many is are there accepts “this” is also
.indexOf(“is”)- checks index no of word from start (returned index 2 of this)
.lastIndexOf(“is”)- checks index no of word from end
.replace(/ is/g” are”)- replace is with are (if not given space replaces “this is also as “thare”)
.charAt(5)- return single letter at the given index
.slice()- works same as array slice
.substr(1,5)- first parameter is start index and second is length
.substring(1,4)-
.toString- Convert array to string
Rest parameter:- you can pass as much as arguments to a variable it will be created into array (…c) passed in function only
Spread operator:- for concatenation of array it is used
Class methods-
Prototype-simply normal method is declare.
Constructor method- it do not need to call, properties are defined in it .automatically calls
Static method- method is static cannot access it by creating object outside it. Can access it by only parent class name
Derived class – the class which inherit properties and methods of other classes. Extends keyword is used to inherit.
Super() method- used to access data of parent class.
Promise():-two parameters are there resolve and reject. which both shows o/p in their respective cases. Three stages are
there pending, fulfilled, unfulfilled. Two call back functions are there .then with resolve .catch with reject