+ 1

Java Script Comparsion Operators

select.onchange= function(){ (select.value==="black")?update("navy","gold","white"):update("red","indigo","white"); My question is what is the "?" doing on this function. The code is part of a theme changer

21st Jan 2020, 9:08 PM
Leonardo Monterey
Leonardo Monterey - avatar
3 Respuestas
+ 2
select.onchange = function() { (select.value === "black") ? update("navy, "gold", "white") : update("red", "indigo", "white"); } It's called the ternary operator and is basically the same as an if-statement select.onchange = function() { if (select.value === "black") update("navy", "gold", "white"); else update("red", "indigo", "white"); } These two codes does exactly the same.
21st Jan 2020, 9:15 PM
ReimarPB
ReimarPB - avatar
+ 1
WOW!!!!!!
21st Jan 2020, 9:28 PM
Leonardo Monterey
Leonardo Monterey - avatar
0
I looked all over my notes couldn't find it and then I Quarantine the code and it gave some error message. Thnaks I was kinda stumped. I did figure it was working as an else statement.
21st Jan 2020, 9:30 PM
Leonardo Monterey
Leonardo Monterey - avatar