I've studied many sources but still I'm confused. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I've studied many sources but still I'm confused.

P: Truthy and falsy statement Javascript.

8th May 2020, 7:18 AM
Rajnish Ranjan
Rajnish Ranjan - avatar
3 Answers
+ 4
It involves type coercion. Which is one of trickiest thing in JavaScript. In the example, wordcount is of type Number. console.log(typeof wordCounter); //number But if we put wordCount alone in the if condition span, we will are converting it into a boolean. console.log(Boolean(wordCount)); //false For 0, it is type coerced to false; For any other number, even negative or decimal, they are type coerced to true. So, in short, the solution of this exercise would be change the 0 in first line to any number other than 0, say 1. And then run the test.
8th May 2020, 7:55 AM
Gordon
Gordon - avatar
+ 3
Would you mind providing a context for your question? For example, a particular reference so we can discuss its examples?
8th May 2020, 7:40 AM
Gordon
Gordon - avatar
0
Q. Change the value of wordCount so that it is truthy. This value should still be a number. ------------------- let wordCount = 0; if (wordCount) { console.log('Great! You've started your work!'); } else { console.log('Better get to work!'); }
8th May 2020, 7:45 AM
Rajnish Ranjan
Rajnish Ranjan - avatar