Please tell me the meaning of voteable = ( age < 18) ? , and what is the meaning of ? (question mark) here ???????? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please tell me the meaning of voteable = ( age < 18) ? , and what is the meaning of ? (question mark) here ????????

<!DOCTYPE html> <html> <body> <p>Input your age and click the button:</p> <input id="age" value="18" /> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var age, voteable; age = document.getElementById("age").value; voteable = (age < 18) ? "Too young":"Old enough"; document.getElementById("demo").innerHTML = voteable + " to vote."; } </script> </body> </html>

28th Nov 2017, 4:38 PM
Karan Rajput
Karan Rajput - avatar
6 Answers
+ 1
thanks buddy, please,can u explain the meaning of ? (question mark) here.
28th Nov 2017, 5:38 PM
Karan Rajput
Karan Rajput - avatar
+ 1
no problem , brother
28th Nov 2017, 5:45 PM
Karan Rajput
Karan Rajput - avatar
0
The ?: is the ternary operator, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator Before the ? goes the condition, if true then whatever is before the : is used, if false then whatever is after the : is used. It is similar to an if else but this is a 1 liner... usually.
28th Nov 2017, 5:03 PM
Dennis
Dennis - avatar
0
The ? is part of the ternary operator's syntax.
28th Nov 2017, 5:41 PM
Dennis
Dennis - avatar
0
thanks , now i got it :) brother can u suggest me a good website for javascript other than w3schools
28th Nov 2017, 5:42 PM
Karan Rajput
Karan Rajput - avatar
0
I wish I could help you there but I don't program in javascript most of the time. So I don't know alot about it :(
28th Nov 2017, 5:44 PM
Dennis
Dennis - avatar