Let's walk through a few examples of logic that will calculate which value is smaller:
The basic if-conditional:
let a = 6;
let b = 2;
let smaller = null;
if(a < b) {
smaller = a;
} else {
smaller = b;
}
console.log(smaller)
Using a Ternary Conditional:
let smaller = a < b ? a : b;
console.log(smaller)
Using Math.min operation
let smaller = Math.min(a,b);
console.log(smaller)
Multiplying Booleans and Number?
let smaller = a*(a<b) + b*(b<=a);
console.log(smaller)
// 6*(6<2) + 2*(2<=6)
// 6*(false) + 2*(true)
// 0 + 2
// 2
Question:
- What is this example above called?