Untitled Document
Untitled Document
lenght
Const mean=(a,b,c,d)=>{
Return a+b+c+d}
Internal style in head
External style in next page
Inline style in same line
2 types of selectors (.) (#)
Class can be called multiple times
Id called only once
Center in center
Sup superscribt
Sub subscript
Alt write in exchange for image
Meter bar with value filled
Table
tr
Thead
th
Tbody
Td
name=”gender”
Select
Option
Optgroup
File
Fieldset
Legend
Required
placeholder
Autofocus
Readonly
Disabled
Check
Min
Max
Maxlength
Video
Control
Preload
Muted
Loop
Poster
Iframe
Details
Summary
Datalist
Input list=id name id datalist
©
™
®
 
 
background: url('download (1).jpg') no-repeat top center;
background-size: cover;
background-attachment: fixed;
Linear gradient
Text shadow
text-shadow: x-axis y-axis blur color;
Background-size:cover image on whole page
box-shadow: x-axis y-axis blur range red;
Excess paragraph
overflow-y: scroll;
overflow-x: hidden;
Transform
Used only once
transform: translate(100px,100px);
transform: skew(0.3turn,0.3turn);
transform: skew(30deg,30deg);
transform: skew(30rad,30rad);
transform: rotate(90deg);
Size
transform: scale(1.5);
transform: scaleX(1.5);
transform: scaleY(1.5);
Position absolute
Position of parent
Left right to parent
Position relative
Position to itself
Left and right to itself
Position fixed
Position of parent
Left right to parent
clear: both;
No text on left and right
position: sticky;
top: 0px;
Always on top
Always give top
column-count: 5;
column-gap: 14px;
column-fill: auto;
First fill data in given width then remaining and adjust the column count accordingly
column-rule: 5px solid;
Border between columns
column-width: 50px;
Only works when column count is not used
h2{
column-span: all;
}
Resize:both: change width and height of text if excess text by using icon
Text-indent: give space before first word
animation-name: contain;
animation-duration: 5s;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-fill-mode: forwards;
animation-direction: alternate-reverse;
animation-timing-function: linear;
/* or ease */
Grid
display: grid;
grid-template-columns:150px 150px 150px 150px 150px;
grid-column-gap: 10px;
grid-row-gap: 10px;
grid-column-start: 1;
grid-column-end: 3;
Join two columns from 1 grid to second grid
Min-height
max-height
<script type="text/javascript">
alert("welcome to fbise");
</script>
Option ok
confirm("login to fbise");
Option ok and cancel
var name;
name="ayesha batool";
document.write(name);
alert(name);
<div id="main">
sdada
</div>
<script type="text/javascript">
var x= document.getElementById("main").innerHTML;
console.log(x);
</script>
Result only sdada
If not used innerHTML so it will result whole code of div on console
<div id="main">
ayesha
</div>
<div id="main">
batool
</div>
var x = document.getElementById("main").innerHTML;
<div class="main">
<h1>ayesha</h1>
</div>
<div class="main">
<h1>batool</h1>
</div>
var x = document.getElementsByClassName("main")[0].innerHTML;
Result is ayesha
var x="hello";
var y="everyone";
console.log(x+y);
Result helloeveryone
<input type="text" name="name" id="name">
<button onclick="funname()">greet</button>
function funname(){
var x=document.getElementById("name").value;
alert(x);
}
parseInt(val1)
name: <i id="whatever">whatever</i>
array
var cars = [];
cars = ["sdfdsa", "DSfsd", "sdfs"];
alert(cars[0]);
var house = new Array();
house = ["asda", "sdas", "asda"];
for(var i=10;i<10;i++){
document.write(i+"</br>");
}
No output
while(i<5){
document.write(i++);
}
var arr=["m","S","s","w","q","a"];
alert(Array.isArray(arr));
Result true
Remove a
// var flag=arr1.reverse();
var flag=arr1.shift();
alert("flag: " + flag);
flag=arr1.shift();
alert("flag: " + flag);
Result m,S
function test() {
setInterval(function () {
alert("hello");
}, 5000)
}
Show after 5s after one press
function test() {
setTimeout(function () {
alert("hello");
}, 2000)
}
Show after delay of 2s one time
function showTime() {
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
var session = "AM";
console.log(d);
if (h > 12) {
h = h - 12;
}
if (h >= 12) {
session = "PM";
}
h = h < 10 ? "0" + h : h;
m = m < 10 ? "0" + m : m;
s = s < 10 ? "0" + s : s;
var time = h + ":" + m + ":" + s + ":" + session;
document.getElementsByTagName('h1')[0].innerHTML = time;
setTimeout(showTime, 1000);
}
Clock ticking
#main{
margin-top: 50px;
cursor: pointer;
transition: 2s;
background-color: aquamarine;
}
function modify() {
document.getElementById("main").style.fontSize = "100px";
}
function unmodify() {
document.getElementById("main").style.fontSize = "50px";
}
Change fontsize of div
<button onclick="start()">start</button>
<button onclick="stop()">stop</button>
var my;
function start() {
my = setTimeout(
function () {
document.write("sda")
}, 5000
)
document.getElementById("main").style.fontSize = "100px";
}
function stop() {
clearTimeout(my);
alert("time stopped");
}
<h1 id="h1"></h1>
<button onclick="stop()">stop</button>
var my = setInterval(count, 1000);
var c = 0;
function count() {
document.getElementById('h1').innerText = c;
c++;
}
function stop() {
clearInterval(my);
}
Stop watch
function test(){
var height=screen.availHeight;
alert(height);
}
function test(){
var height=Math.PI;
alert(height);
}
var x = {
firstName: 'John',
secondName: 'Bagira',
fullName: function () {
return this.firstName + ' ' + this.secondName;
}
};
alert(x.fullName());
function counter() {
document.getElementById("counter").innerText = i;
i++;
}
document.getElementById('btn').addEventListener('mouseenter', function
() {
document.getElementById('counter').style.background = "red";
})
document.getElementById('btn').addEventListener('mouseleave', function
() {
document.getElementById('counter').style.background = "black";
document.getElementById('counter').style.color = "white";
})
function stop() {
document.getElementById('btn').removeEventListener('click',counter);
alert('stop');
}
function printPage() {
window.print();
}
function val(elem) {
document.getElementById('res').innerText = elem.value
if (isNaN(elem.value) || elem.value.length > 10) {
alert("Please enter a valid");
}
}
function test() {
var data = num.value;
try {
if (isNaN(data)) {
throw "no a number";
}
else {
if (data < 5 || data > 10) {
throw "out of range";
}
}
}
catch (err) {
document.getElementById('res').innerText = err;
}
finally {
num.value = "";
}
function testing() {
var clas = test.getAttribute('class');
// document.getElementById("res").innerHTML = clas;
if (clas == 'red') {
test.setAttribute('class', 'blue');
}
else{
test.setAttribute('class', 'red');
}
}
pattern.exec(str);
var student={
firstName:"john",
lastName:"dsdds" ,
Age:2,
greeting: function () {
return this.firstName + " " + this.lastName;
}
};
console.log(student['firstName']);
console.log(student.greeting());
Result john
students.push(obj1);
var stu=students[0];
for(var key in stu){
console.log(key+"="+stu[key]);
}
this.car = "Honda";
var garage = {
car: "suzuki",
getcar: function () {
return this.car;
},
};
console.log(garage.getcar());
var obj=garage.getcar;
console.log(obj());
var newgarage=garage.getcar.bind(garage);
console.log(newgarage());
{
var x = 2;
}
// x CAN be used here
{
let x = 2;
}
// x can NOT be used here
let x = 0;
var x = 0;
Example
var x = 2; // Allowed
let x = 2; // Allowed
let x = 2; // Allowed
}
Meaning: You can use the variable before it is declared:
Example
This is OK:
carName = "Volvo";
var carName;
Example
carName = "Saab";
JavaScript const variables must be assigned a value when they are declared:
Correct
const PI = 3.14159265359;
Incorrect
const PI;
PI = 3.14159265359;
Constant Arrays
You can change the elements of a constant array:
Example
cars[0] = "Toyota";
cars.push("Audi");
//Create an Object
const person = {
firstName:"John",
lastName:"Doe",
age:50, eyeColor:"blue"
}
// Create a copy
const x = person;
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
delete person.age;
// Create an Object
const person = {
name: "John",
age: 30,
city: "New York"
};
// Create an Array
const myArray = Object.values(person);
// Display the Array
document.getElementById("demo").innerHTML = myArray;
Example
const fruits = {Bananas:300, Oranges:200, Apples:500};
// Create an Object
const person = {
name: "John",
age: 30,
city: "New York"
};
// Stringify Object
let myString = JSON.stringify(person);
// Display String
document.getElementById("demo").innerHTML = myString;
Example
Person.nationality = "English";
Try it Yourself »
To add a new property, you must add it to the constructor function prototype:
Example
Person.prototpe.nationality = "English";
Example
this.lastName = name;
myMother.changeName("Doe");
Example
this.lastName = name;
}
myMother.changeName("Doe");
Example
let answer1 = "It's alright";
The backslash escape character (\) turns special characters into string
characters:
\\ \ Backslash
Templates are strings enclosed in backticks (`This is a template string`).
Example
let text =
`The quick
brown fox
jumps over
// x is a string
let x = "John";
// y is an object
let x = "John";
Try it Yourself »
let x = "John";
(x == y) true or false?
Try it Yourself »
//H result
//72 result
//result banana
If a parameter is negative, the position is counted from the end of the string:
//result xxx5
To replace all matches, use a regular expression with a /g flag (global match):
Example
let text = "Please visit Microsoft and Microsoft!";
Example
Returns false:
text.startsWith("world", 5)
Example