Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there any equivalent of ?? operator as exists in C# in JavaScript to defeat 'undefined' checking? For example:

var count = something ?? 0;
like image 855
Hans Avatar asked May 22 '15 10:05

Hans


People also ask

What is operators in C?

C operators are one of the features in C which has symbols that can be used to perform mathematical, relational, bitwise, conditional, or logical manipulations. The C programming language has a lot of built-in operators to perform various tasks as per the need of the program.

What is the or operator in JavaScript?

The logical OR ( || ) operator (logical disjunction) for a set of operands is true if and only if one or more of its operands is true. It is typically used with boolean (logical) values.

Is there any operator in JavaScript?

An operator is capable of manipulating a certain value or operand. Operators are used to perform specific mathematical and logical computations on operands. In other words, we can say that an operator operates the operands. In JavaScript operators are used for compare values, perform arithmetic operations etc.


1 Answers

Use logical OR

var count = something || 0;
like image 120
Zee Avatar answered Oct 02 '22 09:10

Zee