37
loading...
This website collects cookies to deliver better user experience
if (car === 'audi' || car === 'BMW' || car === 'Tesla') {
//code
}
if (['audi', 'BMW', 'Tesla', 'grapes'].includes(car)) {
//code
}
if(obj && obj.tele && obj.tele.stdcode) {
console.log(obj.tele .stdcode)
}
if (name !== null || name !== undefined || name !== '') {
let second = name;
}
const second = name || '';
switch (number) {
case 1:
return 'Case one';
case 2:
return 'Case two';
default:
return;
}
const data = {
1: 'Case one',
2: 'Case two'
};
//Access it using
data[num]
function example(value) {
return 2 * value;
}
const example = (value) => 2 * value
function height() {
console.log('height');
}
function width() {
console.log('width');
}
if(type === 'heigth') {
height();
} else {
width();
}
(type === 'heigth' ? height : width)()
if(amount === null) {
amount = 0;
}
if(value === undefined) {
value = 0;
}
console.log(amount); //0
console.log(value); //0
console.log(amount || 0); //0
console.log(value || 0); //0
let label;
if (amt > 0) {
label = 'profit';
} else {
label = 'loss';
}
const label = amt > 0 ? 'profit' : 'loss';
const arr = [1, 2, 3];
for(let i=0; i<arr.length; i++) {
console.log(arr[i]);
}
const arr = [1, 2, 3];
arr.forEach((val) => console.log(val));
const num1 = parseInt("100");
const num2 = parseFloat("11.11");
simply use + operator
const num1 = +"100";
const num2 = +"11.11";