JavaScript logical and tricky interview questions

https://www.youtube.com/watch?v=riloPTtAuAM

by Chintan Upadhayay

JavaScript

//#1
var x;
var x = 10;
console.log(x);// 10

//#2 , Because variable has golobal scope and we decalring again an again , but leteral not allowed that..but in differnt scope we can do

/* 
var xy;
let xy = 10;
console.log(xy); //ERROR: dentifier 'xy' has already been declared" */

//#3

/* Objects and array, on the other hand, are assigned by reference, so changes made through one reference affect all references pointing to the same object.

Because both has same meomry reference
*/


/*
let arr1 = [1, 2, 3];
let arr2 = arr1;

console.log(arr1); // [1, 2, 3]
console.log(arr2); // [1, 2, 3]

arr1.push(4);

console.log(arr1); // [1, 2, 3, 4]
console.log(arr2); // [1, 2, 3, 4] (both updated)

//or 

let obj1 = { name: 'John' };
let obj2 = obj1;

console.log(obj1); // { name: 'John' }
console.log(obj2); // { name: 'John' }

obj1.name = 'Jane';

console.log(obj1); // { name: 'Jane' }
console.log(obj2); // { name: 'Jane' } (both updated)

/* //When you assign a Primitive Types (e.g., numbers, strings, booleans):
 to a variable, you're working with the actual value:
 
 independent copies /Own copy in memory
 
 Primitive types are assigned by value, and changes to one variable do not affect the other. 

 */
 
/* 
let a = 10;
let b = a;  // 'b' gets a copy of the value in 'a'


console.log(a); // 10
console.log(b); // 10

// If we later change the value of a to 20, it doesn't affect the value of b. This is because primitive types are assigned by value, meaning they are independent of each other.

a = 20;

console.log(a); // 20
console.log(b); // 10 (unchanged) */


//#4

/* let c = 3;

let d =  new Number(3);

console.log(c==d); // True , both has same value

console.log(c===d);// False, Checking Type , d has object type since we added new

 */
 
 //#5
 
 let name ;
 nmae = {}; // It's behave new variable 
 console.log(name); //Undefined, because decalare initial value always is undefined
 
 //#6 


function fruit(){
	console.log("Orange");
}

fruit.name =...