ternary operator in javascript
condition ? ifTrue : ifFalse//ternary operator syntax and usage:
condition ? doThisIfTrue : doThisIfFalse
//Simple example:
let num1 = 1;
let num2 = 2;
num1 < num2 ? console.log("True") : console.log("False");
// => "True"
//Reverse it with greater than ( > ):
num1 > num2 ? console.log("True") : console.log("False");
// => "False"// example:
age >= 18 ? `wine` : `water`;
// syntax:
// <expression> ? <value-if-true> : <value-if-false>var variable;
if (condition)
variable = "something";
else
variable = "something else";
//is the same as:
var variable = condition ? "something" : "something else";condition ? doThisIfTrue : doThisIfFalse
1 > 2 ? console.log(true) : console.log(false)
// returns falseFullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",
Also in JavaScript:
- jquery change text of div
- >Error: Unknown require: ./New ES6 Class Features (in module /App.js) (/App.js:2)
- email validation using regex in javascript
- scroll to top in react
- react native scroll to
- npm start react
- can i use hooks with expo in react native
- how to create an array in javascript
- convert associative array to json javascript
- move file from one folder to another in aws s3 nodejs
- array sum javascript
- arrow keys function javascript
- onclick open link js
- react native webview
- status discored jks
- how to disable cash through get request in angular
- how to capitalize string in javascript
- how to install node js in ubuntu
- choropleth map of india which shows current date confirmed cases in every state json api python.
- code to add to cart by javascript
- javascript pass function as parameter
- razor pages and javascript
- react loop through array
- particle js