ternary function javascript
//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"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 false
Also in JavaScript:
- conditional style react native
- react props.children proptype
- convert string to array js
- how to make fake binary
- nextjs starter
- threemeshphonematerial url image three js
- js console log input value
- javascript seo url parameters
- tuple angular
- mathematically create bezier curve javascript
- how to get unique values from array in javascript without duplicate value
- template JSP form
- array length for boolean in javascript
- find in js
- javascript disable right click
- add firebase javascript
- route in component react
- angularjs filter array of objects based on name prop
- most popular letter in str javascript
- add an image to a div with javascript
- javascript iterate object key values
- how to get the last element of an array in javascript
- material ui align icon with text
- george will turn g years old in year k