Simple To Memorize - Js
Simple To Memorize - Js
p {
text-align: center;
color: red;
}
#para1 {
text-align: center;
color: red;
}
.center {
text-align: center;
color: red;
}
[Link] {
text-align: center;
color: red;
}
* {
text-align: center;
color: blue;
}
element element div p Selects all <p> elements inside <div> elements
element>element div > p Selects all <p> elements where the parent is a <div> element
element+element div + p Selects the first <p> element that are placed immediately after
<div> elements
element1~element2 p ~ ul Selects every <ul> element that are preceded by a <p>
element
div p {
background-color: yellow;
}
div > p {
background-color: yellow;
}
div + p {
background-color: yellow;
}
div ~ p {
background-color: yellow;
}
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited link */
a:visited {
color: #00FF00;
}
/* selected link */
a:active {
color: #0000FF;
}
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
p::first-letter {
color: #ff0000;
font-size: xx-large;
}
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
[Link]::first-letter {
color: #ff0000;
font-size: 200%;
}
The example above will display the first letter of paragraphs with class="intro", in red
and in a larger size
p::first-letter {
color: #ff0000;
font-size: xx-large;
}
a[target] {
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
background-color: yellow;
}
The following example selects all <a> elements with a target attribute
a[target="_blank"] {
background-color: yellow;
}
[class|=top] {
background: yellow;
}
Note: The value has to be a whole word, either alone, like class="top", or followed by a
hyphen( - ), like class="top-text".
<Router history={history}>
</Router>
Array to object:
------------------
Object to Array :
-----------------
const person = {
firstName: 'John',
lastName: 'Doe'
};
prototypical inheritance
[Link]
Array to String :
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let text = [Link](); // Banana,Orange,Apple,Mango
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
String to Array :
--------------------
[Link]("Microsoft", "W3Schools");
[Link](/MICROSOFT/i, "W3Schools");
[Link](/Microsoft/g, "W3Schools");
string methods :
----------------
[Link];
[Link](7, 13);
[Link](7, 13);
[Link](7);
[Link]("Microsoft", "W3Schools");
[Link]();
[Link](" ", text2);
[Link]();
[Link](4,"x");
[Link](4,"x");
[Link](0);
[Link](0);
[Link](",")
Array methods:
------------------
[Link]();
[Link](" * ")
[Link]()
[Link]("Kiwi");
[Link]();
[Link]("Lemon");
delete fruits[0];
[Link](myBoys)
[Link](2, 0, "Lemon", "Kiwi");
[Link](1);
Number.POSITIVE_INFINITY
-Number.MAX_VALUE
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
const food = { beef: '🥩', bacon: '🥓' }
// "Spread"
{ ...food }
// "[Link]"
[Link]({}, food)
// "JSON"
[Link]([Link](food))
[Link](cloneFood);
// { beef: '🥩', bacon: '🥓' }
[Link](cloneFood);
// { beef: '🥩', bacon: '🥓' }
valueOf() method
[Link]("p")
"use strict"
var det = { name:"Tom", ID:"E1001" };
var copy = [Link]({}, det);
[Link](copy);
for (let val in copy) {
[Link](copy[val])
}
var o1 = { a: 10 };
var o2 = { b: 20 };
var o3 = { c: 30 };
var obj = [Link](o1, o2, o3);
var o1 = { a: 10 };
var obj = [Link](o1);
obj.a++
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
[Link](val1 === val2) // return false
the concept of hoisting does not apply to scripts that are run in the Strict Mode.
o/p:
number
object
var val = new String(string);
[Link]
function employee(id, name) {
[Link] = id;
[Link] = name;
}
var emp = new employee(123, "Smith");
[Link] = "smith@[Link]";
charAt()
charCodeAt()
[Link]( "string" )
[Link]( "This is beautiful string");
match()
replace() - need to check
const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const regex = /[A-Z]/g;
const found = [Link](regex);
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
let result1 = /Hello/.exec(text);
o/p:
----
(1,2): pp
(-2,2): y.
(1): pples are round, and apples are juicy.
(-20, 2): nd
(20, 2): d
o/p :(1,2): p
(0,10): Apples are
(5): s are round, and apples are juicy
[Link]() - This method returns the primitive value of a String object.
[Link]([Link]('Hello'));
[Link]([Link]('Hello',5));// checks 'Hello' only in first 5 characters
[Link]([Link]('hell'))
[Link]([Link]('Hell'));
[Link]([Link]('or'));
[Link]([Link]('or',1)) // starts searching 'or' from index 1
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
function fn() { return "Hello World"; }
[Link](`Message: ${fn()} !!`);
[Link](function(val,index) {
[Link](val)
})
[Link]() //reverses the array element
[Link]("Printing Reversed array....")
[Link](function(val,index){
[Link](val)
})
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
var total = [0, 1, 2, 3].reduce(function(a, b){ return a + b; });
[Link]("total is : " + total );
[0, 1, 2, 3].reverse()
o/p:
-----
After adding 1: orange,mango,water,banana,sugar,tea
removed is:
unshift() method adds one or more elements to the beginning of an array and returns the
new length of the array.
var arr = new Array("orange", "mango", "banana", "sugar");
var length = [Link]("water"); // length : 5
var numbers = [1, 2, 3];
var oddNumber = [Link]((x) => x % 2 == 1); // o/p : 1
"use strict"
for (let i of [Link]('hello')) {
[Link](i)
}
o/p :
-------
h
e
l
l
o
"use strict"
var nums = [1001,1002,1003,1004]
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
for(let j in nums) {
[Link](nums[j])
}
let locations=['Mumbai','Hyderabad','Chennai']
let [l1,...otherValues] =locations
let name1,name2;
[name1,name2] =names
let first=10,second=20;
[second,first] = [first,second]
var identifier = {
Key1:value, Key2: function () {
//functions
},
Key3: [“content1”,” content2”]
}
Like all JavaScript variables, both the object name (which could be a normal variable)
and the property name are case sensitive. You access the properties of an object with a
simple dot-notation.
var person = {
firstname:"Tom",
lastname:"Hanks",
func:function(){return "Hello!!"},
};
In ES6, assigning a property value that matches a property name, you can omit the
property value.
var foo = 'bar'
var baz = { foo }
[Link]([Link])
function Car() {
[Link] = "Ford"
}
var obj = new Car()
[Link] = "F123"
var roles = {
type: "Admin", // Default value of properties
displayType : function() {
// Method which will display type of role
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
[Link]([Link]);
}
}
// Create new role type called super_role
var super_role = [Link](roles);
super_role.displayType(); // Output:Admin
"use strict"
var det = { name:"Tom", ID:"E1001" };
var copy = [Link]({}, det);
[Link](copy);
for (let val in copy) {
[Link](copy[val])
}
var o1 = { a: 10 };
var o2 = { b: 20 };
var o3 = { c: 30 };
var obj = [Link](o1, o2, o3);
Unlike copying objects, when objects are merged, the larger object doesn’t maintain a new
copy of the properties. Rather it holds the reference to the properties contained in the
original objects
let student = {
rollno:20,
name:'Prijin',
cgpa:7.2
}
let customers= {
c1:101,
c2:102,
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
c3:103
}
let emp = {
id:101,
address:{
city:'Mumbai',
pin:1234
}
}
let {address} = emp;
let company='TutorialsPoint'
[Link]([Link]('Tutorial'))
[Link]([Link]('orial',3))
let company = 'TutorialsPoint'
[Link]([Link]('Point'));
[Link]([Link]('Tutor',5))//5 is length of string in string
'TutorialsPoint' only first 5 chars are verified
let company='TutorialsPoint'
[Link]([Link]('orial'))
[Link]([Link]('orial',4))// search string will be searched from the
index 4 in main string
let name="Kiran-"
[Link]([Link](3));
[Link]([Link](Infinity))//false
[Link]([Link](-Infinity))//false
[Link]([Link](NaN))//false
[Link]([Link](123))//true
[Link]([Link]('123')) // evaluates to false
[Link](isFinite('123')) // evaluates to true,global function
[Link]([Link]('123'))//false
[Link]([Link](NaN))//true
[Link]([Link](0/0))//true
[Link]([Link]('10.3meters')); // 10.3
[Link]([Link]('abc10.3xyz')); // NaN
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
[Link]([Link]('10meters')) //10
[Link]([Link]('abc10meters')) //NaN
[Link](-Infinity) // -1
[Link]([Link](-3.5)) // -3
let marks = [10,20,30,40,50,60]
[Link]([Link](0,2,4)) //destination,source start,source end(excluding)
// [ 30, 40, 30, 40, 50, 60 ]
[Link]([Link](2,4)) // destination , source start
o/p
7.5
8.5
6.5
9.5
[Link]([Link](10))
[Link]([Link](10,20,30))
[Link]([Link](10))
[Link]([Link](10,20,30))
o/p:
[10]
[10, 20, 30]
const obj_arr ={
length:2,
0:101,
1:'kannan'
}
-- [Link](obj_arr) //{0: 101, 1: "kannan", length: 2}
const arr = [Link](obj_arr)
-- [Link](arr) // [101, "kannan"]
for(const element of arr){
[Link](element); // 101
// kannan
}
[Link]([Link]('Javascript')) // ["J", "a", "v", "a", "s", "c", "r", "i",
"p", "t"]
let setObj = new Set(['Training',10,20,20,'Training'])
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
[Link]([Link](setObj)) // ["Training", 10, 20]
[Link]([Link]([10,20,30,40],n=>n+1)) //[11, 21, 31, 41]
getTime()
Returns the numeric value of the specified date as the number of milliseconds since
January 1, 1970, [Link] UTC
[Link]( 24 )
[Link]()
var dt = new Date(1993, 6, 28, 14, 39, 7);
[Link]( "Formated Date : " + [Link]() ) //Formated Date : Wed Jul 28 1993
o/p:
Formated Date : 7/28/1993
o/p:
7/28/1993, [Link] PM
This method returns the primitive value of a Date object as a number data type, the
numbePr of milliseconds since midnight 01 January, 1970 UTC.
[Link]( x ) ;
[Link]( x ) ;
[Link](x);
[Link](x)
[Link](7.7)
[Link]( x ) ;
[Link](x1, x2,...)
[Link]((x1, x2,...)
[Link]();
Number.MAX_VALUE
Number.MIN_VALUE
[Link];
Number.NEGATIVE_INFINITY
Number.POSITIVE_INFINITY
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
[Link]()
[Link]()
[Link]("10")
[Link]()
var num3 = 177.237
[Link]("[Link]() is "+[Link]()) // 177
[Link]("[Link](2) is "+[Link](2)) // 177.24
[Link](0b001)
o/p:
1
[Link](0o010)
o/p :
8
function sum(...args) {
let sum = 0;
for (let arg of args) sum += arg;
return sum;
}
//General way
render() {
return(
<MyInput onChange={[Link](this) } />
);
}
//With Arrow Function
render() {
return(
<MyInput onChange={ (e) => [Link](e) } />
);
}
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
let city = 'Tokyo';
[Link];
let city = 'Tokyo';
[Link];
city[0];
city[3];
'hello'.toUpperCase();
'LOL'.toLowerCase();
' omg '.trim();
'spider'.indexOf('i'); //2
'vesuvius'.indexOf('u');
'cactus'.indexOf('z');
"pancake".slice(3); //cake
"pancake".slice(0, 3); //pan
// Making an array:
const colors = ["red", "orange", "yellow"];
colors[0];
push(value)
pop()
unshift(val)
shift()
const seatingChart = [
['Kristen', 'Erik', 'Namita'],
['Geoffrey', 'Juanita', 'Antonio', 'Kevin'],
['Yuma', 'Sakura', 'Jack', 'Erika']
]
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
}
}
const testScores = {
keenan: 80,
damon: 67,
kim: 89,
shawn: 91,
marlon: 72,
dwayne: 77,
nadia: 83,
elvira: 97,
diedre: 81,
vonnie: 60
}
let total = 0;
let scores = [Link](testScores);
debugger
for (let score of scores) {
total += score;
}
const deleted = [Link](index, 1);
const newTodo = prompt('Ok, what is the new todo?');
const index = parseInt(prompt('Ok, enter an index to delete:'));

const deleted = [Link](index, 1);
[Link](`Ok, deleted ${deleted[0]}`);
if (typeof x !== 'number' || typeof y !== 'number')
function makeBetweenFunc(min, max) {
return function (num) {
return num >= min && num <= max;
}
}
let innerfunc=makeBetweenFunc(3,6);
[Link]('number falls in interval (3,6) ',innerfunc(8));
function bankRobbery() {
const heroes = ['Spiderman', 'Wolverine', 'Black Panther', 'Batwoman']
function cryForHelp() {
let color = 'purple';
function inner() {
for (let hero of heroes) {
[Link](`${color}, PLEASE HELP US, ${[Link]()}`)
}
}
inner();
}
cryForHelp();
}
bankRobbery()
const movies = [
{
title: 'Amadeus',
score: 99
},
{
title: 'Stand By Me',
score: 85
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
},
{
title: 'Parasite',
score: 95
},
{
title: 'Alien',
score: 90
}
]
const person = {
firstName: 'Viggo',
lastName: 'Mortensen',
fullName: function () {
return `${[Link]} ${[Link]}`
},
shoutName: function () {
setTimeout(() => {
//keyword 'this' in arrow functions refers to the value of 'this' when the
function is created
[Link]("'this' in arrow function",this);
[Link]([Link]())
}, 1000)
}
}
[Link]()
[Link]()
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20];
[Link](function (el) {
if (el % 2 === 0) {
[Link](el)
}
})
[Link](function (movie) {
[Link](`${[Link]} - ${[Link]}/100`)
})
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
}
return min;
})
const exams = [80, 98, 92, 78, 77, 90, 89, 84, 81, 77]
function sum(...nums) {
return [Link]((total, el) => total + el)
}
sum(1,2,3) // 6
// SPREAD IN ARRAYS
const cats = ['Blue', 'Scout', 'Rocket'];
const dogs = ['Rusty', 'Wyatt'];
const dataFromForm = {
email: 'blueman@[Link]',
password: 'tobias123!',
username: 'tfunke'
}
const newUser = { ...dataFromForm, id: 2345, isAdmin: false }
[Link] = function() {
return `OMG!!! ${[Link]()}!!!!! AGHGHGHG!`;
};
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
//We can overwrite an existing Array method like pop (not a good idea):
[Link] = function() {
return 'SORRY I WANT THAT ELEMENT, I WILL NEVER POP IT OFF!';
};
const nums = [ 6, 7, 8, 9 ];
[Link](); // "SORRY I WANT THAT ELEMENT, I WILL NEVER POP IT OFF!"
const response = await fetch(`${FIREBASE_DOMAIN}/[Link]`);
const data = await [Link]();
if (![Link]) {
throw new Error([Link] || 'Could not fetch quotes.');
}
[Link]('div')
[Link](newImg);
const allImages = [Link]('img');
const squareImages = [Link]('square');
const links = [Link]('p a');
[Link]('hide');
const usernameInput = [Link];
[Link]('click', function (e) {
[Link] === 'LI' && [Link]();
})
[Link](img)
typeof "John Doe" // Returns "string"
typeof 3.14 // Returns "number"
typeof true // Returns "boolean"
typeof 234567890123456789012345678901234567890n // Returns bigint
typeof undefined // Returns "undefined"
typeof null // Returns "object" (kind of a bug in JavaScript)
typeof Symbol('symbol') // Returns Symbol
var x = 3;
var y = "3";
x - y //Returns 0 since the variable y (string type) is converted to a number type
var x = 220;
var y = "Hello";
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
var z = undefined;
if (x && y) {
[Link]("Code runs"); // This block runs because x && y returns "Hello" (Truthy)
}
if (x || z) {
[Link]("Code runs"); // This block runs because x || y returns 220(Truthy)
}
eval()
parseInt()
parseFloat()
escape()
unescape()
var x = 50;
var y = 30;
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]
return [Link] > [Link] ? 1 : -1;
} else {
return [Link] < [Link] ? 1 : -1;
}
});
Convert web pages and HTML files to PDF in your applications with the Pdfcrowd HTML to PDF API Printed with [Link]