38
loading...
This website collects cookies to deliver better user experience
[1, 2, 3].includes(3, 0, 7); // true
[1, 2, NaN].includes(NaN); // true
[0,+1,-1].includes(42); // false
async function foo() {
const result1 = await new Promise((resolve) => setTimeout(() => resolve('1')))
const result2 = await new Promise((resolve) => setTimeout(() => resolve('2')))
}
foo()
async function foo() {
try {
const bar = await new Promise((resolve) => setTimeout(() => resolve('1')));
}
catch(e) {
console.log(e)
}
}
foo()
var person = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };
Object.values(person);
// ["Hemanth","HM","Earth","Human"]
let { fname, lname, ...rest } = { fname: "Hemanth", lname: "HM", location: "Earth", type: "Human" };
fname; //"Hemanth"
lname; //"HM"
rest; // {location: "Earth", type: "Human"}
const obj1 = {a:10,b:20}
const obj2={c:30}
const clone_obj={...obj1}
const obj3 = {...obj1,...obj2}
console.log(clone_obj) // {a: 10, b: 20}
console.log(obj3) // {a: 10, b: 20, c: 30}
fetch(url)
.then()
.catch()
.finally(() => console.log(
I'm always called!));
const array1 = [1,2,[3,4,[5,6]]]
console.log(array1.flat(2)) // [1,2,3,4,5,6]
import('/modules/my-module.js')
.then((module) => {
// Do something with the module.
});
const smartphones = {
brands: {
apple: true
}
}
console.log(smartphones.companies?.motorola) // output is: undefined
console.log(null || 'not false value'); // 'not false value'
const orgStr = 'JavaScript, often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled and multi-paradigm.';
let newStr2 = orgStr.replaceAll('JavaScript', 'TypeScript');
console.log(newStr2); // 'TypeScript, often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. TypeScript is high-level, often just-in-time compiled and multi-paradigm.'