Falsey values vs null, undefned, or empty string
- by user687554
I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully understand them. Currently, I have some code that looks like this:
var fields = options.fields || ['id', 'query'];
I need to identify if fields is null, undefined, or has a length of 0. I know the long way is to do:
if ((fields === null) || (fields === undefined) || (fields.length === 0)) {
...
}
My question is, is the following the same:
if (!fields) {
...
}
Thank you!