//#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 =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.