Miscellaneous
function test() {
var a = (b = 0);
a++;
return a;
}
test();
console.log(typeof a); //undefined
console.log(typeof b); //number
//---------------------------------------------
function test1() {
setTimeout(() => console.log(x));
let x = 5;
}
// test1(); //5
//----------------------------------------------
const arr = [1, 2, 3];
delete arr[0];
delete arr[1];
delete arr[2];
console.log(arr); //[ <3 empty items> ]
console.log(arr.length); //3
//----------------------------------------------
const arr1 = [];
arr1.x = 10;
console.log(arr1); //x: 10
console.log(arr1[0]); //undefined
//----------------------------------------------
function test3() {
if (constructor) console.log("hello");
else console.log("Byee");
}
test3(); //hello
//--------------------------------------------
const fn = () => {
if (function test() {}) {
console.log("Okay?");
console.log(typeof test); //function
} else console.log("Not okay");
};
fn(); //Okay?
//---------------------------------------------
const fn1 = () => {
const sentence = "This, India; Great";
return sentence.split(/[,;]/);
};
console.log(fn1()); //[ 'This', ' India', ' Great' ]
//--------------------------------------------
var x = 10;
const fn3 = () => {
x = 5;
console.log(x); //5
};
fn3();
console.log(x); //5
var a = 10;
console.log(a); // 10
function a() {
let a = 20;
}
console.log(a); // 10
console.log(a()); // typeError: a is not a function
console.log('A' + 1); // NaN
console.log(NaN == NaN); // false
console.log(NaN === NaN); // false
const obj = {
name: "JavaScript",
getName: function() {
return this.name;
},
};
const getName = obj.getName;
console.log(getName()); // Calling function outside object
console.log(obj.getName()); // Calling function within object
/*
undefined
JavaScript
*/
const obj = { a: 1 };
console.log(obj.b ?? obj.a);
console.log(obj.b || obj.a);
/*
1
1
*/
var a = 10;
function test() {
if (1) {
a = 20;
function a (){}
a=29
}
}
test();
console.log(a); //10