Use Multiple Conditional Ternary Operators Javascript 1

Use Multiple Conditional Ternary Operators Javascript

// Use Multiple Conditional Ternary Operators Javascript.


function checkSign(num) {

	return num > 0 ? "positive" : num < 0 ? "negative" : "zero";

}

console.log(checkSign(10));
console.log(checkSign(-10));
console.log(checkSign(0));

Here is what the above code is Doing:
1. The function checkSign() takes a number as an argument.
2. The function returns a string based on the value of the number.
3. If the number is greater than 0, the function returns "positive".
4. If the number is less than 0, the function returns "negative".
5. If the number is equal to 0, the function returns "zero".

Similar Posts