This question already has answers here:
Why does "[] + {} === {} + []" evaluate to "true"? [duplicate]
(2 answers)
What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?
(5 answers)
Closed 5 years ago.
a couple of days ago I had a Javascript exam and the last question was:
When you evaluate the expression {} + [] what do you get?
Error
null
0
undefined
I've tested in vscode but I can get an answer :(
If you simply open your developer tools and type that expression in, you will see the return value as 0.
Related
This question already has answers here:
How is almost everything in Javascript an object?
(6 answers)
Closed 5 months ago.
I tested this today and I don't understand the behaviour. For me, that should be an error.
const a = 1;
a.test = 1;
console.log(a)
console.log(a.test)
Someone have the answer ?
you can define properties pretty much anything, but in this case you are assigning it to a number which doesn't actually hold properties.
This question already has answers here:
JavaScript 'hoisting' [duplicate]
(5 answers)
Javascript function scoping and hoisting
(18 answers)
What are the precise semantics of block-level functions in ES6?
(2 answers)
Closed 1 year ago.
I have come across a very strange JavaScript code. Its execution result is completely different from what I expected. I want to know why.
var a = 1999;
{
console.log(a);
a = 2020;
function a() {}
a = 2021;
}
console.log(a); //Why 2020?
This question already has answers here:
What is the point of using labels in javascript (label: stuff here) outside switches?
(2 answers)
labeled statement - incorrect definition?
(1 answer)
Closed 3 years ago.
In javascript what does : mean except ternary condition.
Like if we write
$:1 returns 1
undefined:1 returns 1
a:1 returns 1
but
1:1 returns error
can someone please explain the scenario.
This question already has answers here:
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 4 years ago.
I can't seem to find anything in the documentation to understand why the { and } characters are wrapped around variables on some examples I've seen. Can anyone example why we would do that?
For example:
const {app} = require('./app/app.js');
This question already has answers here:
What does "!" operator mean in javascript when it is used with a non-boolean variable?
(5 answers)
What is an exclamation point in JavaScript?
(2 answers)
Closed 5 years ago.
Coming from java, learning angular/typescript: The ! negates booleans or boolean expressions. This is, according to my research, the same in javascript/typescript. But what does the following method do?
isSelected(product: Product): boolean {
if (!product || !this.currentProduct) {
return false;
}
return product.sku === this.currentProduct.sku;
}
What is !product? Product is coming in as a method parameter and then it is asked, if product is not product, or wtf should that mean? :D