notes Available at :
Column1
[Link]():-
[Link] ():-
[Link]():-
[Link]():-
[Link]():-
[Link]() and
[Link]():-
[Link]():-
[Link]():
[Link]() and
[Link]():-
[Link]
Column2
[Link]('Your code Took');
[Link]('Hello console');
[Link](4+34);
[Link](34);
[Link](true);
[Link]([34,2,1,2]);
[Link]({harry: 'this', marks:34});
[Link]({harry: 'this', marks:34});
[Link]('This is a warning');
// [Link]();
[Link]('Your code Took');
// [Link](566<189, 'Age >189 is not possible')
// [Link]('This is an error'
[Link]
Access Attribute value of button
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get the value of the onclick attribute of the button element.</p>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> Internet Explorer 8 and earlier does not support the getNamedItem
method.</p>
<p id="demo"></p>
<script>
function myFunction() {
var a = [Link]("BUTTON")[0];
var x = [Link]("onclick").value;
[Link]("demo").innerHTML = x;
}
</script>
</body>
</html>
Column1
here it will return myFunction which is the value of
onlick attribute of BUTTON[0]
Creating , Removing , replacing element
Differenc
e
between
append
append and
append
child
[Link]
[Link]/ibn_
abubakre
/append-
vs-
appendch
ild-a4m
appendChild
createElement('li')
[Link]=
[Link]=
[Link]()
[Link](element)
[Link](element)
createTextNode('mytext')
[Link](element2)
[Link](child1, child2)
[Link](childNode)
[Link]('href')
[Link]([Link])
[Link]([Link]) // "Some text"
.childnodes[0].childnodes[1]
in Body tag, \n(enter) is a text node under an element
[Link]
Removing , replacing element
Column1 Column2
[Link]('this is tut 16');
let element = [Link]('li');
let text = [Link]('I am a text node');
[Link](text)
// Add a class name to the li element
[Link] = 'childul';
[Link] = 'createdLi';
[Link]('title', 'mytitle');
// [Link] = '<b>Hello this is created by harry</b>';
// [Link] = '<b>Hello this is created by harry</b>';
let ul = [Link]('[Link]');
[Link](element);
// [Link](ul)
// [Link](element)
let elem2 = [Link]('h3');
[Link] = 'elem2';
[Link] = 'elem2';
let tnode = [Link]('This is a created node for elem2');
[Link](tnode);
[Link](elem2);
let myul = [Link]('myul');
[Link](element, [Link]('fui'));
[Link]([Link]('lui'));
let pr = [Link]('href');
[Link]('id');
[Link]('title', 'myelem2title');
[Link](elem2, pr);
// quick quiz
// create a heading element with text as "Go to CodeWithHarry" and create an a tag o
initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="container">
<h1 id="heading"> Welcome to Code With Harry</h1>
<div id="myfirst" class="child red good"
id="first">child 1
<ul class="this">
<li class="childul">this</li>
<li class="childul">is</li>
<li class="childul">a</li>
<li class="childul">list </li>
<li class="childul">of my dreams</li>
</ul>
</div>
<div class="child">child 2</div>
<div class="child red">child 3</div>
<div class="child">child 4</div>
<form action="[Link]" method="post">
<a href="//[Link]">Go to Code With
Harry</a>
<br>
<br>
Search this website: <input type="text"
name="Hello" id="">
<input type="button" value="submit">
</form>
</div>
<br>
<div class="no">this is a dummy div1</div>
<div class="no">this is a dummy div2</div>
<div class="no">this is a dummy div3</div>
</body>
Column3 Column4 Column5
or elem2');
" and create an a tag outside it with href = "[Link]
Column1
Difference between append() and appendChild()
Difference between for-in and for-of and for-each?
difference between es5 and es6 in javascript
What is Constructor
Difference between map ,filter and reduce
Difference between map() and foreach()
Column2
[Link]
for-in is used to get the index of each element of array, and for -of
is used to get the elements of array
[Link]
Constructor is a function to create an object,
ex. When we declare an array and iitialise it. It call a function
function Array()
If try filter using map, will return using true or false for each
element of array
on the other hand we can filter out data using filter function
Column3 Column4 Column5
[Link]
[Link]
concat
constructor
copyWithIn
entries
every
some
fill
filter
First index satisfying condition of find find
findIndex
Joins the elements of
indexof each element
reduceRight()
[Link]
Column1
arr3 = [Link](arr2)
[Link]
[Link](target,start,end)
The [Link]() method returns an Array Iterator object with key/value pairs.
[Link](myfun)
myfun(value){return value>18 }
some elements of array must fullfil condition
[Link]('myvalue')
[Link](()=>)
[Link](()=> )
[Link]((n)=>n>4)
[Link](()=>{} )
[Link](arr1).filter(n=>n>7)
[Link](myvalue)
[Link]('apple')
[Link](ArrayName)
[Link]('And')
[Link]()
[Link]
[Link]('mystring')
[Link]()
prototype
[Link]((accumulator, currentvalue)=> accumulator +currentvalue)
[Link]((acc,currentVal )= >currentVal -acc}
[Link]()
removes the first element of the array
[Link](start, end)
[Link]((a,b)=>a-b)
[Link](index, howmany_toRemove, item1, ....., itemX)
[Link]()
[Link]('item1','item2')
Arr = []
Str = 'mynameis rakesh'
for (i in Str) {
[Link](Str[i])
}
[Link](Arr)
<script>
var array = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 8, 8];
[Link]("Before filtering non unique values: " + array);
var unique = [Link]((value, index) => {
return [Link](value) === [Link](value);
});
[Link]("After filtering non unique values: " + unique);
</script>
var array = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 8, 8];
arr2 = new Set(array) // new Set
arr3 = ([Link](arr2)) // create an array from Set
arr=[5,10,15,20,25,30]
[Link]([Link](…arr))
arr=[5,10,15,20,25,30]
[Link]([Link]((a,b)=>{return b-a}))
Column2 Column3
arr3 = [Link](arr2)
function Array() { [native code] }
arr = ['ab', 'cd', 'ef']
for (i in arr) [Link]([Link]().next().value)
const ages = [32, 33, 16, 40];
[Link](checkAge) // Returns false
function checkAge(age) {
return age > 18;
}
[Link]((el,indx)-> el>30} 1
each element is replaced with myvalue
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr2 = []
arr2 = [Link]((num) => num > 4)
[Link](arr2)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr2 = []
arr2 = [Link]((n) => n > 3.2)
[Link](arr2)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr2 = []
arr2 = [Link]((n) => n > 4)
[Link](arr2)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr2 = []
arr2 = [Link](arr).filter((n) => n > 7)
[Link](arr2)
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[Link]([Link](8)) //true
[Link]([Link](12)) //false
returns index of first occurance
const fruits = ["Banana", "Orange", "Apple", "Mango"];
[Link](fruits) // Returns true
const fruits = ["Banana", "Orange", "Apple", "Mango"];
[Link](" and ");
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const keys = [Link]();
for (let i of keys) [Link](i)
returns lngth of array
returns index of last occurance of cretaria meet
[Link]
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
[Link]([Link]((accumulator, currentvalue) =>
accumulator + currentvalue))
const fruits = ["Banana", "Orange", "Apple", "Mango"];
[Link]();
var array = [1, 2, 2, 3, 4, 5, 46, 16,
27, 8, 18, 8];
[Link]((a, b) => a - b)
[Link](array)
replace original array
at index position, will remove(if any) and add items
The [Link]() method returns a string with all
array values separated by commas:
push at the beginning of array
String is an array of characters
to get Unique values seprately
Get Unique values from array
Get Maximum of array
using [Link] and spread array
Get Maximum of array using sort
typeof and instance of
constructor
type of is for primitive data type
instanceof is for object data type
Column1
function fun(a, b, c) {
[Link] = a;
[Link] = b;
[Link] = c;
}
obj = new fun('rakesh', 96643, 'developer')
[Link](obj instanceof fun)
[Link](obj instanceof Object)
typeOf('rakesh')
ect data type
Column2 Column3 Column4 Column5
returns true
returns true
String
Column1
Create Object Method 1
Create Object Method2
Create Object Method 3
Create Object method4
method 5
Singleton
Create Object pattern:
Get number of Keys of object
traversing of entries of Object
arguments object
Make first character capital
Column2 Column3
var myobj ={}
var myobj = new Object()
Function myobj(a,b) {[Link]=a,[Link]=b}
obj1 = new myobj('rakesh',96643)
[Link]([Link])
[Link]([Link])
class myobj {
constructor(a, b) {
[Link] = a;
[Link] = b
}
get nm() { return [Link] }
}
obj2 = new myobj('rakesh', 96643)
[Link]([Link])
var obj = new function(){
[Link]='rakesh'
}
[Link]([Link](obj).length)
for(key in obj) [Link](obj[key])
function fun() {
for (key in arguments) [Link](arguments[key])
}
fun(1, 2, 3, 'a')
[Link]([Link](0).toUpperCase() + [Link](1))
Column4
onstorage event
[Link] = function(e) {
[Link]('The ' + [Link] +
' key has been changed from ' + [Link] +
' to ' + [Link] + '.');
};
OR
[Link]('storage',function(e) {[Link]([Link], [Link], [Link]
[Link]([Link], [Link], [Link])}
Get width and height of image in JS
and height of image in JS
HTML
<div class="container">
<img
src="[Link]
39.1605559903.fit_scale.size_760x427.png" alt="" srcset="">
</div>
JS CONSOLE
function myfun() {
[Link]("hello2")
var mycont = [Link]('container')
var myimage = mycont[0].getElementsByTagName('IMG')
[Link](myimage[0])
var width_ = myimage[0].clientWidth
var height_ = myimage[0].clientHeight
[Link](width_)
}
Column4 Column5
Column1
String to Title case
first character to upp
Column2
var str = "foo bar baz"
[Link](
[Link](' ')
.map(w => w[0].toUpperCase() + [Link](1).toLowerCase())
.join(' ')
)
[Link]([Link](0).toUpperCase() + [Link](1))
Column3 Column4 Column5
var str = 'rakesh ahuja'
[Link]([Link](' ').map((el, inx, arr) => [Link](0).toUpperCase() +
[Link](1).toLowerCase()).join(' '))
Column6
function sum(...args) {
let accum = 0;
for (i in args) {
accum += args[i];
}
return accum;
}
[Link](sum(1, 2, 3))
[Link](sum(1, 2, 3, 4))
[Link](sum(1, 2, 3, 4, 5))
When Numbers of arguments are not fixed, then we use rest parameters with … (dot dot dot)
or another syntax below
function sum(...args) {
return [Link]((acc, el, ind, arr) => { return acc + el }, 0)
}
[Link](sum(1, 2, 3))
[Link](sum(1, 2, 3, 4))
[Link](sum(1, 2, 3, 4, 5))
var url = new URL('[Link]
var params = new URLSearchParams([Link])
[Link]([Link]('b')) //2
[Link]([Link]('a')) //["3","9"]
[Link]([Link]('c')) //true
[Link]([Link]('d', 5))
[Link]([Link]('d'))
[Link](...[Link]())
[Link](...[Link]())
<div id="outer" style="border: 1px solid
#ff0000;padding:14px">
<ul id="ulid">
<li id="liid1">1</li>
<li id="liid2">2</li>
<li id="liid3">3</li>
<li id="liid4">4</li>
<li id="liid5">5</li>
<li id="liid6">6</li>
<li id="liid7">7</li>
<li id="liid8">8</li>
<li id="liid9">9</li>
</ul>
</div>
var outer = [Link]('outer')
[Link]('click', (e) => {
var target = ([Link])
[Link] = '/' + target
})
var mypromise = new Promise((resolve, reject) => {
let error = false great
if (!error) {
resolve('great');
} else { reject('error'); }
});
[Link]((msg) => [Link](msg)).catch((err) => { [Link](err) })
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, 'One'); (3) ["One", "two", "three"]
});
const promise2 = new Promise((resolve, reject) => { Promise is fullfilled when all the pomises are resolved, then values
setTimeout(resolve, 100, 'two'); are accumulated in value of then
});
const promise3 = new Promise((resolve, reject) => { If any one promise is rejected , then overall it is not fullfilled
setTimeout(resolve, 100, 'three');
});
[Link]([promise1, promise2, promise3]).then((values) => {
[Link](values);
});
const promise1 = new Promise((resolve, reject) => setTimeout(resolve, 100,
'quick'));
const promise2 = new Promise((resolve, reject) => setTimeout(resolve, 200, 'ok'));
const promise3 = new Promise((resolve, reject) => setTimeout(resolve, 500, 'slow'));
const promises = [promise1, promise2, promise3];
[Link](promises).then((value) => [Link](value)).catch(err=>) all are resolved with 'any'
const promise1 = new Promise((resolve, reject) => setTimeout(reject, 100, 'quick'));
const promise2 = new Promise((resolve, reject) => setTimeout(resolve, 200, 'ok'));
const promise3 = new Promise((resolve, reject) => setTimeout(resolve, 500, 'slow'));
const promises = [promise1, promise2, promise3];
one promise is reject with 'any'
[Link](promises).then((value) => [Link](value)); still Promise is fullfilled.
let x = 8
function fun(x) {
var element = 0
Prime factors label1: for (let i = 2; i < x; i++) {
element = (x % i)
if (element == 0) return ('not prime')
}
return ('prime')
}
function factors(x) {
const arr = []
[Link](0, 1, 1)
[Link](arr)
for (let i = 0; i < 5; i++) {
Fibonacci series let a;
let b;
a = Number([Link]([Link] - 2, [Link] - 1))
b = Number([Link]([Link] - 1, [Link]))
let c = a + b
[Link](c)
[Link](c)
}
[Link](arr)
let a = 32
let b = 28;
let m = [Link](a, b)
HCF
const arr = []
for (let i = 2; i <= m/2; i++) {
if ((!(a % i)) && (!(b % i))) [Link](i)
}
[Link]([Link](...arr))
arr1 = [3, 5, 1, 2, 8, 9, 7, 1]
Merge and Sort array arr2 = [13, 25, 11, 12, 18, 19, 27, 11]
let arr3 = [Link](arr2)
[Link]((a, b) => a - b)
[Link](arr3)
let x = 5;
let y = 7;
Swap two numbers without using third number x = x + y;
y = x - y;
x = x - y;
[Link](x, y)
reverse a string STR = 'rakesh'
[Link](([Link](STR).reverse()).join(''))
reverse the words in string myword = 'My name is rakesh'
[Link]([Link](' ').reverse().join(' '))
str = 'rakeshahuja'
get unique characters from a string let set1 = new Set([Link](str))
[Link]([Link](set1).join(''))
check if string is palindrom str = 'momom'
[Link](([Link]('')).reverse().join('') === str)
let a = 5;
random number between 5 and 7 let b = 7;
[Link]([Link](a + (b - a) * [Link]()))
arr = [4, 2, 5, 7, 8, 9, 11, 12]
[Link]((a, b) => a - b)
const arr2 = []
for (let i = 1; i <= arr[[Link] - 1]; i++) {
if ([Link](i)) continue
else [Link](i)
}
[Link](arr2)
check missing numbers in an array
arr = [1, 2, 3, 4, 5, 0]
get sum of largest two numbers of array let largest = [Link](...arr)
let second = ([Link]((a, b) => b - a))[1]
[Link](largest + second)
n = 1000
arr = []
for (let i = 1; i <= n; i++) {
count number of zeroes from 1 to n let x = (([Link]()).split('')).filter((el, indx) => el == "0")
// [Link](x)
if ([Link]("0")) [Link](x)
}
[Link]([Link])