question mark and colon in javascript
const isBlack = false;const text = isBlack ? 'Yes, black!' : 'No, something else.';console.log(text);// "No, something else."
question mark and colon in javascript
const isBlack = false;const text = isBlack ? 'Yes, black!' : 'No, something else.';console.log(text);// "No, something else."
javascript question mark
//This is what is called a 'Conditional operator'
let result = condition ? value1 : value2
// ^^ ^^ ^^
let result = 1 == 2 ? "YES" : "NO!"
console.log(result) //output: "NO!"
//Basically a short form of an if-else statment
question mark in javascript
boolean statement ? true result : false result;
/*
For example, if we take this if statement:
*/
if (a > b) {
result = x;
} else {
result = y;
}
// can be also writen:
result = a > b ? x : y;
single if statement js true false
condition ? exprIfTrue : exprIfFalse
question mark operator javascript
voteable = (age < 18) ? "Too young":"Old enough"
// condition ? if true : if false
question mark in javascript
(condition) ? {code for YES} : {code for NO}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us