How many ways to declare an array : 3 ways
1). const a=[1] const b=[2] console.log(a+b); // 12 console.log(typeof (a+b)); //string Explanation: Whenever we use an addition operator with an array, JavaScript will internally use the .toString method to convert it into a string. the above expression becomes "1"+"2", and these two strings are concatenated, and it will print 12
const a=[1,2,4] const b=[0,2,3,4] const c=[9,3,4] console.log(a+b+c); //1,2,40,2,3,4 first array elements displayed and separated by coma(,) and second array first element is concatenated with first array last element and displayed remaining elements separated coma(,)
1.2). const arr =[1,2,3] const str = "1,2,3" console.log(arr == str); //true console.log(arr === str); // false
1.3). console.log([1,2]+![]); // 1,2false [] -> true ![] -> false
2). console.log(3+4+"5"); //75 console.log((3+4+"5"+2)); // 752 console.log(typeof (3+4+"5"+2)); //string
console.log([]=="") // true console.log("" == false); // true console.log([]== false); // true console.log(![]); // false
3). x++ console.log(x); //Nan var x =10 explanation: x++ -> undefined++ -> Nan JavaScript is unable to convert undefined to a number
4). let a = 10 > 9 > 8 console.log(a === true); //false console.log(a == true); //false Explanation : In JavaScript, the associativity will be from left to right. 10 is greater than 9 will be compared, 10 is always greater than 9 so it will become true. In JavaScript, whenever we compare the Boolean value with the numeric value, true will be converted to 1 and false will be converted to 0. Now our expression becomes 1 greater than 8. 10 > 9 = true true > 8 = 1 > 8 = false true -> 1 false ->0