Plus operator in javascript [duplicate] - javascript

This question already has answers here:
What is the purpose of a plus symbol before a variable?
(4 answers)
Closed 6 years ago.
What does if (t == +t) { ... } mean?
Sorry for asking such a simple question, but I have searched for "plus operator" and tried to evaluate it in javascript myself, but I cannot guess what the purpose is.

Its a unary operator and it coerces t to a number from a string. It has the same effect as:
if (t == Number(t)) { ... }
For more information: Is plus sign in +process a typo in Node.js documentation on domains?

Related

What does this syntax mean in Javascript? [duplicate]

This question already has answers here:
What does the comma operator do in JavaScript?
(5 answers)
What does this symbol mean in JavaScript?
(1 answer)
Using &&'s short-circuiting as an if statement?
(6 answers)
Closed 4 years ago.
I have javascript code and I found the following line :
I'm a bit confused about the syntax
e = k.attr("data-icon"), e && (a.icon = e),
I understand the first part : k.attr("data-icon") but not the rest.
Can any one tell me what does that mean please ?
cheers,

regex for string is confusing [duplicate]

This question already has answers here:
Learning Regular Expressions [closed]
(1 answer)
Reference - What does this regex mean?
(1 answer)
Javascript Regex: How to put a variable inside a regular expression? [duplicate]
(9 answers)
Closed 4 years ago.
Is there any difference between the two regexes?
isFunctionKey(funKey) {
return /^('funKey')|([01][1-9]|2[0-4])$/.test(funKey);
}
and
isFunctionKey(funKey) {
return /^(funKey)|([01][1-9]|2[0-4])$/.test(funKey);
}
HINT: Look into return statement funkey; one is in quotes and the other is not.

What is the difference between double negation and checking if the variable is truthy directly? [duplicate]

This question already has answers here:
Why use !! to coerce a variable to boolean for use in a conditional expression?
(3 answers)
What is the difference between if(!!condition) and if(condition)
(3 answers)
Why use if (!!err)?
(3 answers)
Closed 5 years ago.
I noticed my colleagues are writing code with double negation in conditions, for example:
else if(colType == 'link'){
value = !!data ? $(data).attr('href') : '';
}
In cases like this, is there a chance that the boolean result of data can be different from !!data?

How can '+myVar;' be a valid syntax [duplicate]

This question already has answers here:
Explain +var and -var unary operator in javascript
(7 answers)
Closed 6 years ago.
I just got a bug that took some of my time to spot my searching filters weren't working because of the following code :
queryObject.search='valid==true';+searchQuery;
The good syntax is to mive the ';' in the string :
queryObject.search='valid==true;'+searchQuery;
The reasn why i didn't spot that is because the earlier line of code didn't triggered any javascript console error. So it seems it's a valid syntax.
So here is my question, how can this be a valid syntax ?
+something is an expression using the plus unary operator.
Its general purpose is to convert a value, for example a string, to a number.
+ is unary operator, which tries to get numeric value from variable.
There is a thread about it.

Difference between "==" and "===" in java script [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Javascript === vs == : Does it matter which “equal” operator I use?
Hi
I am not clear why there are two == and === comparator operators in java script.
The equality operator == coerces, or converts the data type temporarily to see if it's equal to the other operand whereas the identity operator === doesn't need to do any converting whatsoever since it directly compares them without conversion meaning it's stricter and faster.
2=='2'
true
2==='2'
false

Categories

Resources