From the course: JavaScript: Best Practices for Data

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Compare appropriately for the data type

Compare appropriately for the data type - JavaScript Tutorial

From the course: JavaScript: Best Practices for Data

Start my 1-month free trial

Compare appropriately for the data type

- [Instructor] My code contains a set of if statements that check for values in the data and they only log the relevant values if the check succeeds. Each one of these checks a different data type and for each one, I've simply checked for truthiness. But that's not always going to give me the most reliable code. My first if statement on line 10 checks the truth value of data.warning. In this case the value is a Boolean so simply checking the value makes sense. I could add double-negation before the value to insure I'm getting a Boolean, but when I know I'm working with a Boolean, that's redundant and I already have the no-extra-Boolean-cast rule set up in ESLint to flag that. So I'll take those back out and leave line 10 as is. On line 13 data.notes is a string and I want to check if I have a non-empty string before logging it's value. An empty string is falsy, so here I'm checking if the string is anything other than…

Contents