What is the significance of `:` sign in JS [duplicate] - javascript

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.

Related

In JavaScript what is this method called where you might define a variable or property as such variable_name$ref [duplicate]

This question already has answers here:
Rules for unquoted JavaScript Object Literal Keys?
(6 answers)
What characters are valid for JavaScript variable names?
(12 answers)
Closed 1 year ago.
I am seeing it crop up more and more in code I am going through on a new project (can't share due to contractual reasons) where Ill see something like:
{
prop1: value$ref,
$prop2: null
}
I have see ${prop3} before, but never an example without the brackets. Can anyone provide direction as to what the method is, or the operator is or whatever the case?

Strange console.log behaviour with object and it's field [duplicate]

This question already has answers here:
console.log() async or sync?
(3 answers)
Is Chrome’s JavaScript console lazy about evaluating objects?
(7 answers)
Closed 1 year ago.
I have the strange behavior (as i think) of console.log. So, there is two console.log in my console, first shows PdfViewerApplication object, second shows it's fieid, named eventBus.
So, as you can see second line says that PdfViewerApplication.eventBus right?
Now lets look at first line (before! second) , expand the body of the object and find eventBus field.
Obviously it is not null there, it almost has 2 eventListeners (pagesloaded)!
How is it possible?

What is going on with the 'in' function in javascript? [duplicate]

This question already has answers here:
Why does javascript's "in" operator return true when testing if 0 exists in an array that doesn't contain 0?
(6 answers)
Why does ("a" in ["a","b"]) yield false, and (1 in [1,2]) yield true? [duplicate]
(1 answer)
Closed 3 years ago.
Something that recently broke my code is that I naively thought that:
'+' in ['+','-',...] = true.
The only problem is that it actually evaluates to false!
Someone please help me understand what is going on here!
The in operator returns true if the specified property is in the
specified object or its prototype chain.
Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in

Number functions and other functions issue [duplicate]

This question already has answers here:
Calling the toFixed method on a number literal [duplicate]
(3 answers)
Why can't I access a property of an integer with a single dot?
(5 answers)
Closed 5 years ago.
Can someone logicaly explain why fallowing function return error
50.toFixed(2);
and this not
(50).toFixed(2);
Same happening with other similar number functions

What is the result of this line {} + []? [duplicate]

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.

Categories

Resources