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;


<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>



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

Other Items in javascript
Page Views

This page has been viewed 248 times.

No Items Found.

No Items Found.

No Items Found.

No Items Found.

No Items Found.

Use Multiple Conditional (Ternary) Operators

I actually find if then statements much easier to read than these ones, but these seem more efficient. 

3:18 am, September 27, 2019
Search Code
Search Code by entering your search text above.

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
1. Show your work to the world instead of keeping in your head💆. 2. Do the work consistently👌 3. Respect your work🥰 4. Don't postpone your work 5. Make mistakes 🔥🔥🔥