+ 1
I've studied many sources but still I'm confused.
P: Truthy and falsy statement Javascript.
3 Respuestas
+ 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.
+ 3
Would you mind providing a context for your question?
For example, a particular reference so we can discuss its examples?
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!');
}