What is || operator in javascript [duplicate] - javascript

This question already has answers here:
Logical operator || in javascript, 0 stands for Boolean false?
(2 answers)
What does this symbol mean in JavaScript?
(1 answer)
What does "var FOO = FOO || {}" (assign a variable or an empty object to that variable) mean in Javascript?
(8 answers)
Closed 5 years ago.
let x = process.argv[2] || "abc";
I am new to javascript.
I don't think || is a boolean OR operator here.
What does this line mean? Why using OR on some strings?
Does this mean if process.argv[2] is null, then assign "abc" to x?

Related

When does x not equal x? [duplicate]

This question already has answers here:
JavaScript numeric self equality [duplicate]
(2 answers)
What is the difference between (NaN != NaN) and (NaN !== NaN)?
(5 answers)
Closed 2 years ago.
In auditing the Javascript version of 'verb', (a NURB library,) I happened across this method:
HxOverrides.cca = function(s,index) {
var x = s.charCodeAt(index);
if(x != x) return undefined;
return x;
};
I'm puzzled by the condition,
if(x != x)
When is this ever True?
In further reading, I discovered the Javascript method, "s.charCodeAt(index)" returns the Unicode value of the (index)th character in string 's'. Specifically:
If index is out of range, charCodeAt() returns NaN.
In the console, I tested:
NaN == NaN
I found this to be false. Therefore, as to the question of:
"When does x not equal x?"
the answer (at least in Javascript,) is:
"x != x when x is NaN (not a number)".

Js: What happens when curly brackets enclose the variable declaration? [duplicate]

This question already has answers here:
What does this symbol mean in JavaScript?
(1 answer)
Javascript object bracket notation ({ Navigation } =) on left side of assign
(5 answers)
What is destructuring assignment and its uses?
(3 answers)
Closed 2 years ago.
I am trying to understand the following expression.
const {
TARGET = 'http://localhost:8080',
PORT = 80
} = process.env;
How does variable declaration enclosed by curly brackets work?
And how does the value assignment for process.env works?
Does this type of expression have a name?

clarity on the meaning of this javascript math object syntax [duplicate]

This question already has answers here:
What do ">>" and "<<" mean in Javascript?
(10 answers)
What does the ^ (caret) symbol do in JavaScript?
(5 answers)
What do these JavaScript bitwise operators do?
(3 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 8 months ago.
I was going through a small program and i came across this syntax in javascript.
hash = Math.abs((hash << 2) ^ (hash + y))
please what does it mean?
hash was initially 0; i.e hash = 0;

JavaScript equivalent of ?? operator in C# [duplicate]

This question already has answers here:
Is there a "null coalescing" operator in JavaScript?
(19 answers)
Closed 7 years ago.
Is there any equivalent of ?? operator as exists in C# in JavaScript to defeat 'undefined' checking?
For example:
var count = something ?? 0;
Use logical OR
var count = something || 0;

Difference between != null and !== null in Javascript [duplicate]

This question already has answers here:
Which equals operator (== vs ===) should be used in JavaScript comparisons?
(48 answers)
JavaScript Equality Operator
(3 answers)
Closed 9 years ago.
Splitting hair here, but my editor complains I should use a !== null instead of a != null in a Javascript if statement. What is the difference?
Update
This question has been closed as duplicate, but the other questions supposedly answering my question are not answering it... Check their answers! There is a subtlety here -> null

Categories