# What is the use of truthy and falsy? and The below code is too confusing for me...I'm a begineer and just enrolled my Java script course with Mosh

**URL:** https://forum.codewithmosh.com/t/what-is-the-use-of-truthy-and-falsy-and-the-below-code-is-too-confusing-for-me-im-a-begineer-and-just-enrolled-my-java-script-course-with-mosh/895
**Category:** Uncategorized
**Created:** [November 24, 2020, 9:16pm UTC](https://forum.codewithmosh.com/t/what-is-the-use-of-truthy-and-falsy-and-the-below-code-is-too-confusing-for-me-im-a-begineer-and-just-enrolled-my-java-script-course-with-mosh/895 "2020-11-24T21:16:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![moid](https://avatars.discourse-cdn.com/v4/letter/m/db5fbb/32.png) [@moid](https://forum.codewithmosh.com/u/moid)
#### Post date: [November 24, 2020, 9:16pm UTC](https://forum.codewithmosh.com/t/what-is-the-use-of-truthy-and-falsy-and-the-below-code-is-too-confusing-for-me-im-a-begineer-and-just-enrolled-my-java-script-course-with-mosh/895/1 "2020-11-24T21:16:37Z")

</div>

const array = [0, null, ‘’, 2, 3];

console.log(countTruthy(array));

function countTruthy(array) {

```
let count = 0;

for (let value of array)

    if (value)

        count++;

return count;

```

}

---

<div class="post-metadata">

### Author: ![joshuamwolfe](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/joshuamwolfe/32/243_2.png) [@joshuamwolfe](https://forum.codewithmosh.com/u/joshuamwolfe)
#### Post date: [November 25, 2020, 9:12pm UTC](https://forum.codewithmosh.com/t/what-is-the-use-of-truthy-and-falsy-and-the-below-code-is-too-confusing-for-me-im-a-begineer-and-just-enrolled-my-java-script-course-with-mosh/895/2 "2020-11-25T21:12:38Z")

</div>

Read this.

[Understanding Javascript Truthy and Falsey](https://stackoverflow.com/questions/35642809/understanding-javascript-truthy-and-falsy#:~:text=Quoting%20from%20MDN%20In%20JavaScript%2C%20a%20truthy%20value,List%20of%20falsy%20values%20in%20JavaScript%3A%20From%20MDN)
