Simpler JS boolean based conditions
Nothing new, just the path to nicer code that I always seem to take:
var result;
var big = 4;
var small = 3;
// first attempt
if(big > small){
result = true;
} else {
result = false;
}
// better
result = (big > small) ? true : false;
// awww yeah, nice
result = big > small;
Written by Ben Howdle
Related protips
2 Responses
best:
result = big > small;
over 1 year ago
·
You forgot the intermediary result = (big > small) || false; // ;)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#