js - Use the Conditional (Ternary) Operator

this statement can be used instead of if this else that statements. to me it makes it look a bit more complex when reading it. this is the basic syntax. condition ? statement-if-true : statement-if-false;

function checkEqual(a, b) {
  return a == b ? true : false;
}

HTML

<div id='result' class='mb-3 alert alert-primary'>..</div>
<button onclick='checkEqual(1,2);' class='btn btn-primary mb-1'>Check Equal 1,2</button>
<button onclick='checkEqual(1,1);' class='btn btn-primary mb-1'>Check Equal 1,1</button>

Result

..

External Link for js - Use the Conditional (Ternary) Operator

Other Items in javascript
Page Views

This page has been viewed 359 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
I'm a big believer in energy and the secret and that sort of thing.
Unknown