JSFiddle - React, Tailwind, and code Playground

One line if check.

by Travis Almand

JavaScript

// var is undefined or has string to start
var test;
//var test = 'assign';

// old fashioned if check
// if var is false or undefined assigns string value
//if (!test) {
//	test = 'multi line';
//}

// two line if check with no brackets
// works same as version above
//if (!test)
//	test = 'two line';

// one line using || operator
// if var is false or undefined assigns string value
test || (test = 'one line');

console.log(test);