Professional Documents
Culture Documents
Data types
number
bigint -- for long digits
string --> " ",' '
boolean = true/false
null --- standalone value
undefined -- not assigned
symbol -- use in react-- for find unique
object
// ***********Operations*************
let val = 3
let nagval = -val
console.log(nagval)
// console.log(2+2)
// console.log(2-2)
// console.log(2*2)
// console.log(2**2)
// console.log(2/2)
// console.log(2%2)
console.log("2"+1)
console.log(2+"1")
console.log("1"+2+3)
console.log(2+3+"2")
// console.log(+true)
// console.log(+"")
let a = null
let b = Number(a)
console.log(b)
// console.log(2>1)
// console.log(2>=1)
// console.log(2<1)
// console.log(2<=1)
// console.log(2==1)
// console.log(2!=1)
// console.log("2" >1)
// console.log("a" > "A")
// console.log(undefined == undefined)
// **********Summary************
// Primitive
// console.log(typeof b)
// const f = myfun(){}
let a = "sd"
let b = a
a = "ds"
console.log(b)
console.log(a)
// console.log(gameName.length)
// console.log(gameName.toUpperCase())
// console.log(gameName.charAt(2))
console.log(gameName.indexOf('l'))
const as = gameName.substring(0,4)
console.log(as)
// trim() remove spaces in string
// replace('replaced word',' by replacing word')
console.log(gameName.split('-'))
// const balance = 12
// console.log(balance)
// console.log(balance.toString())
// console.log(balance.toString(16))
// console.log(balance.toFixed(3))
// const a1 = 11121111111
// console.log(a1.toPrecision(1))
// console.log(a1.toExponential())
// console.log(a1.toLocaleString())//US standerd
// console.log(a1.toLocaleString('en-IN'))//INDIAN standerd
// ++++++++++++++++Maths+++++++++++++++
// console.log(Math)
// console.log(Math.random())
// console.log((Math.random()*10) +1)
// console.log(Math.random())
// const min = 10
// const max = 20
// Math.random()*(max-min +1)
// console.log(Math.floor(Math.random()*(max-min +1) ) + min)
// Date
// let myDate = new Date()
// console.log(myDate)
// console.log(myDate.toDateString())
// console.log(myDate.toISOString())
// console.log(myDate.toLocaleDateString())
// console.log(myDate.toLocaleString())
// console.log(myDate.toLocaleTimeString())
// console.log(myDate.toJSON())
// console.log(myDate.getTimezoneOffset())
// console.log(typeof myDate)
// arrays
myArr.push(6)
myArr.pop()
myArr.unshift(0)
myArr.shift()
console.log(myArr.includes(2))
console.log(myArr.indexOf(9))
// marvel_hero.push(dc)
// console.log(marvel_hero)
// console.log(marvel_hero[3][1])
// const all =marvel_hero.concat(dc).concat(a)
// console.log(all)
// spread method
// const all_new =[...marvel_hero,...dc]
// console.log(all_new)
// flat
const another_array = [1,2,3,[4,5,6],7,[6,7,[2,3,4]]]
const real_another_array = another_array.flat(Infinity)
// yaha infinity ke badle finite depth deni chahiye
console.log(real_another_array )
console.log(Array.isArray("1123"))
console.log(Array.from("1123"))
console.log(Array.from({ name:"1123"}))//interesting
let score1 = 1
let score2 = 2
let score3 = 3
console.log(Array.of(score1,score2,score3))
const JsUsers ={
name:"Sid",
// use [] to use key as Symbol either it will be string
"full name" : "Siddharth",// '.' operator se kabhi access nai kar shakte
age: "18",
// [a]: "Ahmedabad"
}
// key and value in this type of object
JsUsers.greeting = function(){
console.log("Hello bro");
}
JsUsers.greeting2 = function(){
console.log(`Hello bro, ${this.name}`);
}
console.log(JsUsers.greeting())
console.log(JsUsers.greeting2())
// singleton
// console.log(igUser)
const regularUser = {
emai : "siddharth@gmail.com",
fullname:{
userkaname:{
firstName:"Sid",
lastName:"Doshi"
}
}
}
// console.log(regularUser.fullname?.userkaname.firstName)
console.log(user[1].email)
console.log(igUser)
console.log(Object.keys(igUser))
console.log(Object.values(igUser))
console.log(Object.entries(igUser))
console.log(igUser.hasOwnProperty('username'))
const course = {
coursname: "js in hindi",
price:"111"
}
// destructure objects
const{price: p} = course
// console.log(price)
console.log(p)
// APIs
// JSON
// {
// "name" : "Siddharth",
// "countsename": "js ion hindi"
// }
// Functions
// defination of function
function sayMyName(){
console.log("Siddharth")
}
// Refrence of function
sayMyName()
function addToNumber(n1,n2){
console.log(n1+n2)
}
function addToNumber2(n1,n2){
// method 1 declare karne ke liye
// let result = n1+n2
// return result
const b = addToNumber2(1,2)
// console.log(b)
function loginmsg(username){
if(username === undefined){
console.log("areh!! naam to do user ko ")
return
}
// or ek tarika
// if(!undefined){
// console.log("areh!! naam to do user ko ")
// return
// }
console.log(loginmsg("raju"))
console.log(loginmsg())
// rest operator ...- for many parameters input which will be store in array
console.log(calculateCartPrice(2))
const user = {
username : "Rajesh",
price:199
function handleObj(anyobject){
console.log(`username is ${anyobject.username} and price is
${anyobject.price}`)
}
handleObj(user)
handleObj({username: "kaju", price:200})
function returnSecondValue(getArray){
return getArray[1]
console.log(returnSecondValue(myNewArr))
// let a = 20
// var b = 30
// const c = 40
// globel scope
if(true){
// block scope
let a = 20
var b = 30
const c = 40
}
// console.log(a)
console.log(b)
// console.log(c)
// nested scope
function one() {
const username = "Siddharth";
function two() {
const website = " youtube";
console.log(username)
}
// console.log(website)
two()
}
// one()
// if(true){
// const username = "Siddharth"
// if( username === "Siddharth"){
// const website = "Youtube"
// console.log(username + website)
// }
// console.log(website)
// }
// console.log(username)
console.log(addone(5))
function addone(num){
return num +1
}
addone(5)
// const user = {
// username: " Sid",
// price : 222,
// // this--current context
// welcomeMsg : function(){
// console.log(`${this.username}, welcome to the website`)
// console.log(this)
// }
// }
// user.welcomeMsg()
// user.username = "Sem"
// user.welcomeMsg()
// console.log(this)
// This value--
// Node environment --{}
// Browser --- window(globel object)
// chai()
console.log(addTwo(1,2))
//
// function chai(){
// console.log(`DB CONNECTED`)
// }
// chai()
(function chai(){
console.log(`DB CONNECTED`)
})();
// globel scope ke pollution ko hatane ke liye iife ka use hota hai --()()
// ; jaruri hai function ko end karne ke liye
// arrow function bhi use kar shakte ho isme
// Javascript execution context
// 1. {}-- globel ex. context -- > valu of this--window
// 2. functional ex. contect
// 3. eval ex. context
let val1 = 10
let val2 = 5
function addNum(n1,n2){
let total = n1+n2
return total
}
// Execution Phase
// val1-- 10
// val2--5
// addNum ---> New variable environment + execution phase
// 1. ---> Memory Phase
// val1 undefined
// val2 undefined
// total undefined
// Call stack
// in Globel execution -- lifo concept last in first out
// if
// if(condition){
// }
// else if{
// }
// else{
// }
// switch(key){
// case value:
// break;
// default:
// break;
// }
// falsy values
// false,0,-0, BigInt 0n, "", null, undefined,NaN
// truthy values
// "0",'false'," ",[],{},function(){}
let val1;
val1 = 5 ?? 10
val1 = null ?? 10
val1 = undefined ?? 10
console.log(val1)
// terniary operator
// condition? true :false
// for loop
// while loop
while (condition){
// statement
}
// do while loop
do{
}while(condition);
// for of
// }
// ["",""]-- string
// [{},{}]-- objects
console.log(map);
// const myObj ={
// 'game1': 'nfs',
// 'game2':'cfs'
// }
const myObj ={
'game1': 'nfs',
'game2':'cfs'
}
// for each
console.log("----------------");
// arrow function
coding.forEach( item => {
console.log(item)
});
const mn = [1,2,3,4,5,6,7,8,9]
mn.forEach(num => {
if(num >4){
mn.push(num)
}
});
// console.log(newmn)
// Reduce
const n = [1,2,3]
console.log(t)
DOM :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Learning</title>
<style>
.bg-black{
background: rgb(20, 20, 20);
color: white;
}
</style>
</head>
<body class="bg-black">
<div >
<h1 class="heading" id="title">Hello me heading hu <span >test
text</span></h1>
<p>Lorem ipsum dolor sit amet.</p>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</body>
<script src="one.js"></script>
</html>
// diagram
// window---> document---> HTML
// HTML---> Head and body
// head--->title and metatags
// title--> textNode
// metatags-->attribute
// Body---->
// div---> attribute (h1 and p are child)
// h1---> textNode and Attribute
// p ---> textNode
// document.getElementById('title')
document.getElementById('title').id
document.getElementById('title').className
document.getElementById('title').getAttribute('id')
document.getElementById('title').setAttribute('class','or kuchh naam')
title.style.backgroundColor = 'green'
title.innerText//only visible text content
title.textContent // all content with hodden text (display: none)
title.innerHTML
document.getElementsByClassName('heading')
document.querySelector('h1')
document.querySelectorAll('h1')// for all h1
document.querySelector('.heading')// all selectors select as CSS
const templilist = document.querySelectorAll('li')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dom learning</title>
<style>
.bg-black{
background: rgba(0, 0, 0, 0.644);
color: white;
}
</style>
</head>
<body class="bg-black">
<!-- <div > -->
<!-- <h1 id="title" class="heading">Dom learning</h1>
<p>Lorem ipsum dolor sit amet.</p>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>
</div> -->
<ul class="language">
<li>Javascript</li>
</ul>
</body>
<script>
// const a= document.querySelector('.parent')
// console.log(a)
// console.log(a.children)
// console.log(a.childNodes);
//
function addLang(langName){
const li = document.createElement('li');
// li.innerHTML=`${langName}`w,pw
li.appendChild(document.createTextNode(langName))
document.querySelector('.language').appendChild(li)
addLang("Python")
</script>
</html>
DOM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM Learning</title>
<style>
.bg-black{
background: rgb(20, 20, 20);
color: white;
}
</style>
</head>
<body class="bg-black">
<div >
<h1 class="heading" id="title">Hello me heading hu <span >test
text</span></h1>
<p>Lorem ipsum dolor sit amet.</p>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</body>
<script src="one.js"></script>
</html>
// diagram
// window---> document---> HTML
// HTML---> Head and body
// head--->title and metatags
// title--> textNode
// metatags-->attribute
// Body---->
// div---> attribute (h1 and p are child)
// h1---> textNode and Attribute
// p ---> textNode
// ***************** Write this code in console*********
// document.getElementById('title')
document.getElementById('title').id
document.getElementById('title').className
document.getElementById('title').getAttribute('id')
document.getElementById('title').setAttribute('class','or kuchh naam')
title.style.backgroundColor = 'green'
title.innerText//only visible text content
title.textContent // all content with hodden text (display: none)
title.innerHTML
document.getElementsByClassName('heading')
document.querySelector('h1')
document.querySelectorAll('h1')// for all h1
document.querySelector('.heading')// all selectors select as CSS
const templilist = document.querySelectorAll('li')
EVENT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>htnml Events </title>
</head>
<body style="background-color: #414141; color: aliceblue;">
<h2>Amazing image</h2>
<div >
<ul id="images">
<li><img width="200px" id="photoshop"
src="https://images.pexels.com/photos/3561339/pexels-photo-
3561339.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load" alt="photoshop"></li>
<li><img width="200px" id="japan"
src="https://images.pexels.com/photos/3532553/pexels-photo-
3532553.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load" alt=""></li>
<li><img width="200px" id="river"
src="https://images.pexels.com/photos/3532551/pexels-photo-
3532551.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load" alt=""></li>
<li><img width="200px" id="owl"
src="https://images.pexels.com/photos/3532552/pexels-photo-
3532552.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load" alt="" ></li>
<li><img width="200px" id="prayer"
src="https://images.pexels.com/photos/2522671/pexels-photo-
2522671.jpeg?auto=compress&cs=tinysrgb&w=1600&lazy=load" alt=""></li>
<li><a style="color: aliceblue;" href="https://google.com"
id="google">Google</a></li>
</ul>
</div>
</body>
<script>
// document.getElementById('owl').onclick = function(){
// alert("owl clicked")
// }
// attachEvent()
// jQuery - on
// document.getElementById('images').addEventListener('click',
function(e){
// console.log("clicked inside the ul");
// }, false)
// document.getElementById('owl').addEventListener('click', function(e){
// console.log("owl clicked");
// e.stopPropagation()
// }, false)
// document.getElementById('google').addEventListener('click',function(e){
// e.preventDefault();
// e.stopPropagation()
// console.log("google clicked");
// }, false)
document.querySelector('#images').addEventListener('click', function(e){
console.log(e.target.tagName);
if (e.target.tagName === 'IMG') {
console.log(e.target.id);
let removeIt = e.target.parentNode
removeIt.remove()
}
})
//removeIt.parentNode.removeChild(removeIt)
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Chai aur code</h1>
<button id="stop">Stop</button>
</body>
<script>
const sayHitesh = function(){
console.log("Hitesh");
}
const changeText = function(){
document.querySelector('h1').innerHTML = "best JS series"
}
document.querySelector('#stop').addEventListener('click', function(){
clearTimeout(changeMe)
console.log("STOPPED")
})
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Chai aur Javascript</h1>
<button id="start">Start</button>
<button id="stop">Stop</button>
</body>
<script>
const sayDate = function(str){
console.log(str, Date.now());
}
clearInterval(intervalId)
</script>
</html>
ADVANCE CONCEPT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" contnt="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.bg-black{
background: black;
color: white;
}
</style>
</head>
<body class="bg-black">
<div>
<h1>Lorem ipsum dolor sit amet,
consectetur adipisicing elit.
Eaque, magni.</h1>
</div>
</body>
<script>
const requestUrl = 'https://api.github.com/users/siddharthdoshi06'
console.log(requestUrl);
// console.log(this.responseText);
const data = JSON.parse(this.responseText);
// URL se jo bhi data aata hai woh object ke badle
// string format me aata hai..!!!
console.table(typeof data)
console.log(data.following)
}
}
xhr.send()
// console.log(xhr.readyState);
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
// Promise
</script>
</body>
</html>
const promise1 = new Promise(function (resolve, reject) {
// Do an async task
// Data Base call, cryptography call, network
// set time out
setTimeout(function () {
console.log("Async task is complete");
resolve();
}, 1000);
});
// 2nd syntex
promise1.then(function () {
console.log("Promise consumed");
}); // .then() is connected to resolve
// 3rd
promise3.then(function (user) {
console.log(user);
});
// 4th
// 5th
})
// }catch(error){
// console.log(error)
// }
// }
// consumePromise5()
// try {
// const response =await
fetch('https://jsonplaceholder.typicode.com/users')
// const data = await response.json()
// console.log(data);
// } catch (error) {
// console.log(error)
// }
// }
// getAllUsers()
// lec 41
fetch('https://jsonplaceholder.typicode.com/users')
.then(function(response){
return response.json();
})
.then(function(data){ console.log(data) })
.catch( (error) => console.log("ERROR")
)
setTimeout(function () {
console.log("Async task is complete");
resolve();
}, 1000);
});
// 2nd syntex
promise1.then(function () {
console.log("Promise consumed");
}); // .then() is connected to resolve
// 3rd
promise3.then(function (user) {
console.log(user);
});
// 4th
## parts of oop
object literal
-Constructor function
-prototype
-Classes
-Instances(new,this)
# 4 pillars
Abstraction
Encapsulation
Inheritance
Polymorphism
function multipleBy5(num){
return num*5
}
multipleBy5.power = 2
console.log(multipleBy5(5));
console.log(multipleBy5.power);
console.log(multipleBy5.prototype);
createUser.prototype.increment = function(){
this.score++
}
createUser.prototype.printMe = function(){
console.log(`price is ${this.score}`);
}
chai.printMe()
/*
Here's what happens behind the scenes when the new keyword is used:
A new object is created: The new keyword initiates the creation of a new
JavaScript object.
A prototype is linked: The newly created object gets linked to the prototype
property of the constructor function. This means that it has access to
properties and methods defined on the constructor's prototype.
The new object is returned: After the constructor function has been called, if
it doesn't return a non-primitive value (object, array, function, etc.), the
newly created object is returned.
*/
const user = {
userName : "Sid",
SignIn: "kiya hai re deva kiya hai",
getUserDetails: function () {
// console.log("Mil gaya re details deva mil gaya re")
// console.log(`User ka naam : ${this.userNmae}`);
console.log(this)
// this ---> current context
}
}
// console.log(user.userNmae);
// // console.log(user.getUserDetails());
// console.log(this)
// // filhaal globel context me kuch nai hai
// // yeah browser me run karoge to bahot kuch milega
function User(userName){
this.userName = userName
return this
}
// const UserOne= User("Sid")
// const UserTwo= User("Hetu")
// yeha constructor function use nai ho raha
// is liye UserTwo data overwrite kar raha hai
// so use new keyword
// because of new keyword:
// ES6
// class User {
// constructor(username, email, password) {
// this.username = username;
// this.email = email;
// this.password = password;
// }
// encryptPassword() {
// return `${this.password}abc`;
// }
// changeUsername() {
// return `${this.username.toUpperCase()}`;
// }
// }
User.prototype.encryptPassword = function () {
return `${this.password}abc`;
};
User.prototype.changeUsername = function () {
return `${this.username.toUpperCase()}`;
};
function User(email,password){
this._email = email;
this._password = password;
Object.defineProperty(this,'email',{
get: function(){
return this._email.toUpperCase()
},
set: function(value){
this._eamil = value
}
})
Object.defineProperty(this,'password',{
get: function(){
return this._password.toUpperCase()
},
set: function(value){
this._password = value
}
})
}
const User = {
_email : "h@h.com",
_pass : "123",
class User{
constructor(username){
this.username = username;
}
logMe(){
console.log(`USERNAME is ${this.username}`)
}
}
addCourse (){
console.log("New course added by sir");
}
}
class User{
constructor(username){
this.username = username;
}
logMe(){
console.log(`USERNAME is ${this.username}`)
}
static createId(){
return '123'
}
}
function Setusername(username){
// complex db call
this.username = username;
}
function createUser(username,email,password){
Setusername.call(this, username)
this.email = email,
this.password = password
BIND
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React</title>
</head>
<body>
<button>Button clicked</button>
</body>
<script>
class React{
constructor(){
this.library = "React";
this.server = "https://localhost:3000"
// Requirement
document
.querySelector('button')
.addEventListener('click',this.handleClick.bind(this))
}
handleClick(){
console.log("Button click");
console.log(this.server);
console.log(this);
}
}
const Sid = {
name:'Siddharth',
Age: 45,
isAlive: true
}
console.log(Sid);
console.log(Object.getOwnPropertyDescriptor(Sid,"name"));
Object.defineProperty(Sid,"name",{
writable:false,
enumerable:false,
configurable:false
})
console.log(Object.getOwnPropertyDescriptor(Sid,"name"));
<button id="orange">
Orange
</button>
<button id="green">
Green
</button>
<script>
// function init(){
// let name = "Siddharth";
// function displayName(){
// console.log(name)
// }
// displayName();
// }
// init()
// Concept of closer
// function outer(){
// let username ="Sid"
// console.log(secret);
// function inner(){
// let secret ="123"
// console.log(username);
// }
// inner()
// function inner2(){
// console.log(username);
// console.log(secret)
// }
// inner2()
// }
// outer()
// console.log(username)
// function makeFunc(){
// const name ="Sid"
// function displayName(){
// console.log(name);
// }
// return displayName
// }
// document.getElementById("orange").onclick = function(){
// document.body.style.backgroundColor = `orange`
// }
// document.getElementById("green").onclick = function(){
// document.body.style.backgroundColor = `green`
// }
function clickHandler(color){
// document.body.style.backgroundColor = `${color}`
document.getElementById("orange").onclick = clickHandler("orange")
document.getElementById("green").onclick = clickHandler("green")
</script>
</body>
</html>