Skip to content

Instantly share code, notes, and snippets.

View shahab570's full-sized avatar

MD SHAHAB UDDIN shahab570

View GitHub Profile
promise.then(
(value) => {
/* run when promise resolved */
},
(error) => {
/* run when promise rejected */
}
);
const promise = new Promise((resolve, reject) => {
has_money = false;
setTimeout(() => {
if (has_money) {
resolve("Here is your car. Enjoy your ride");
} else {
reject("Sorry, I don't have money to buy car");
}
}, 5000);
});
@shahab570
shahab570 / car.js
Last active January 1, 2021 07:05
car promsie
const promise = new Promise((resolve, reject) => {
has_money = true;
setTimeout(() => {
if (has_money) {
resolve("Here is your car. Enjoy your ride");
} else {
reject("Sorry, I don't have money to buy car");
}
}, 5000);
});
function square(x,result = x *x ) {
console.log(result);
}
square(5); //25
square(6) ; //36
@shahab570
shahab570 / test.js
Last active December 29, 2020 13:46
function number() {
return 10;
}
function result (x ,y =number()) {
console.log(x+y);
}
result(2); //12
result(10,20) //30
function identity(name = "John",age = 25) {
console.log(name, " ", age);
}
identity(); //John 25
identity("Harris"); //Harris 25
function abc(x,y) {
if (x === undefined) {
x = 100;
}
if (y === undefined) {
y = 50;
}
console.log(x,y);
}
@shahab570
shahab570 / test.js
Last active December 30, 2020 03:21
function abc(x,y) {
//we used logical OR(||) operator. It returns the first truthy value.
//if first value is undefined, second value is returned
x = x || 100;
// value of x is x which is given at the function call. If not given value is 100
y = y || 50;
// value of y is y which is given at the function call. If not given value is 50
console.log(x,y);
}
@shahab570
shahab570 / test.js
Last active December 30, 2020 03:26
function abc(a,b) { // a and b are called parameters
//code
}
abc(c,d); // c and d are called arguments
//style.css
* {
margin: 0;
padding: 0;
box-sizing: border-box; }
body {
width: 100%;
height: 100vh;
background-color: #0f3057;