This question already has answers here:
What's wrong with var x = new Array();
(5 answers)
What is the difference between condensed arrays and literal arrays?
(3 answers)
Closed 6 years ago.
Is typing "var foo = []" the same as typing "var foo = new Array()"?
Related
This question already has answers here:
Javascript How to define multiple variables on a single line?
(10 answers)
What is the purpose of the var keyword and when should I use it (or omit it)?
(19 answers)
Closed 2 months ago.
Can any one explain why this happens?
// Example 1
(function () {
var a = b = 5;
})();
console.log(b); // Output 5
var a = b = 5 and var b = 5 is totally different?
This question already has answers here:
Does JavaScript pass by reference? [duplicate]
(13 answers)
Is JavaScript a pass-by-reference or pass-by-value language?
(33 answers)
Closed 2 years ago.
I'm new to Javascript
The function is not changing the outer variable
function edit(array, letter){
array = 0;
letter = 'b';
}
let string = 'a';
let array = [1,0,2];
edit(array, string);
console.log(array, string);// Result [1,0,2] not 0 b
This question already has answers here:
Why are two identical objects not equal to each other?
(9 answers)
Closed 4 years ago.
Why it returns false?
let a = new Object()
let b = Object()
console.log(a) // {}
console.log(b) // {}
console.log(a===b) // false
I checked a proto of a and b too and it is the same.
So what is the difference?j
Instance of objects are not the same even:
let a = new Object();
let b = new Object();
console.log(a===b) // false
This question already has answers here:
How to use a variable for a key in a JavaScript object literal?
(16 answers)
Closed 5 years ago.
console.log(a) ; // console window result= 1
console.log(b);// console window result= 2
var c = {a : b};// any recommendations here?
var d = JSON.stringify(c);
d = encodeURIComponent(d);
I need final result of d = {1:2};
You can use computed property
var c = {[a] : b};
This question already has answers here:
Why can't a property be added to a null value?
(2 answers)
Closed 6 years ago.
property myProperty is not assigned to variable foo, foo is an object.
var foo=null;//null is an object
foo.myProperty = "my value";
console.log(typeof foo.myProperty);
A Javascript object should be declared like this
var myObject = {};
Try to modify you code like
var foo = {};
foo.myProperty = "a string";
console.log(typeof foo.myProperty);