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;
Related
This question already has answers here:
What does ${} (dollar sign and curly braces) mean in a string in JavaScript?
(6 answers)
What does this symbol mean in JavaScript?
(1 answer)
Closed 2 years ago.
I have seen ${ } being used in many javascript codes. What exactly does this do?
For example:
updateDisplay(){
if(this.operation != null){
this.previousOperandTextElement.innerText = ${this.previousOperand} ${this.operation};
}
this.currentOperandTextElement.innerText = this.currentOperand;
}
Why would we not use + to concatenate in this case?
It's called a template literal. It achieves the same thing as concatenation but in a more readable manner:
const a = "Hello"
const b = "."
console.log(`${a} World${b}`)
This question already has answers here:
How to convert array to a mathematical computation expression? [duplicate]
(2 answers)
How can I convert a string into a math operator in javascript [duplicate]
(3 answers)
Evaluating a string as a mathematical expression in JavaScript
(26 answers)
Closed 2 years ago.
I am getting an array value after an operation.
let data = formula.map(a => typeof a === 'number' ? result[index++] : a)
My output that I am getting is
data=["6.9","+","7.1","-","3.0"]
I wanted to perform normal math operation on this data like 6.9+7.1-3.0 so my end output will be
endresult = 11
You can use eval and pass a string into it. To create a string from the array you can use join().
var data=["6.9","+","7.1","-","3.0"];
var data1=["6.9","+","7.1","*","3.0"];
console.log(eval(data.join('')));
console.log(eval(data1.join('')));
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;
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?
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