Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

Javascriptt

The document provides a comprehensive overview of JavaScript, covering variable declarations, data types, operators, control structures, functions, objects, and methods. It explains how to manipulate the DOM, utilize string and array methods, and introduces concepts like promises, classes, and destructuring. Additionally, it highlights various ways to display output and handle user interactions through pop-ups and alerts.

Uploaded by

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

Javascriptt

The document provides a comprehensive overview of JavaScript, covering variable declarations, data types, operators, control structures, functions, objects, and methods. It explains how to manipulate the DOM, utilize string and array methods, and introduces concepts like promises, classes, and destructuring. Additionally, it highlights various ways to display output and handle user interactions through pop-ups and alerts.

Uploaded by

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

Javascript

Variable declaration
var fname=”pratik”;

Three ways to display js


1.console.log(a); to display op in console
2.alert(a); display in alert type
3.document.write(a,”<br/>”); display in body doc.write is inline element

To insert any text betn tags using java script


document.getElementById(“h”).innerHTML = “Hello World”;
document- is the html doc
getElementId- act as selector for id
inner.html- for applying changes inside html

Keywords for declaring variable to store value


var- we can redeclare and can also change value
let- we cannot redeclare but can change value
const- we cannot reassign value after its initial assignment.

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.

Split()method- to convert a string to array .


Join()method- to convert an array into string.
Concat()method- joins the two arrays
Sort()method- sorts the array
array.isarray- used to find the given anything is array or not

To delete or blank the array


Arrayname.length=0
To find the no. or posn of element
let a=names.indexOf(“element name”)
To check whether the variable declared is array or not
document.write(Array.isArray(arrayname)) (returns o/p in Boolean format)

Function: it is block of code to perform a particular task


When we create a function that time, we pass value it is called parameter. function tratik(sum)
When we call a function that time, we pass value it is called argument. tratik(sum).

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

Array/Object destructuring :- if we want assign a value of array to a variable we use destructuring

Set method- it removes duplicate values from array


Map method:- return new array we cannot apply conditions in it like comparisions it acts on each and every value.
Filter method- it also returns new array used simply for applying filters. Not acts on each and every value. We apply
conditions in it.

Class- we define methods and properties in it.


Object- we inherit/giveor assign values to the properties

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

You might also like