Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
⊗jsPmCdShCh 122 of 504 menu
◀ ▶

General shorthand checking in JavaScript

The shortened form of checking works for other data types as well. In this case, this data is first converted to a boolean type, and then compared with true. See an example:

let test = 3; if (test) { console.log('+++'); // it will work } else { console.log('---'); }

In fact, the above code is equivalent to the following:

let test = 3; if (Boolean(test) === true) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = 3; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = 'abc'; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = ''; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = 3 * 'abc'; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = null; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = false; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = 0; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = '0'; if (test) { console.log('+++'); } else { console.log('---'); }

Without running the code, determine what will be output to the console:

let test = -1; if (test) { console.log('+++'); } else { console.log('---'); }
← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline