How does this function work in JS?
Hello, I don't understand the function here:
function function1(a, b){
return a*(a<b)
+b*(b<=a);
What exactly does "a*(a<b)" do? That would initially return True/False, right? So if a is less than b, True, and then a* True?!?
Yes, but JavaScript is now a weakly typified Language. The value false is thus simply converted ad hoc into the number 0 when a computing operation is required. The value true in 1.
And now you can figure out what the function is. Tip: you could also make the same with an if expression.
Okay, thanks. Yeah, I know, but I wanted to avoid industry.