Javascript: isFunctions
Tags: javascript, webdev, programming, discuss
Published: 2022-02-23 16:54:29

In every language, we need to validate data before modifying or displaying it.

So, here in the case of javascript also we almost regularly use these functions and we maintain all these in single util class to reuse quickly.

No further theory let’s jump into stuff.

Basically,

{% embed https://gist.github.com/K-Vishwak/a96acce6736dbf7d163cf739e8bbc22c %}

Use the above reference and write `isFunctions` now:

**isNumber**

{% embed https://gist.github.com/K-Vishwak/7b72295c65d131c93a9f7b8da9db81cf %}

(+/-)Infinity is of type number in javascript as if you want to avoid then you can update logic as:

{% embed https://gist.github.com/K-Vishwak/d7a633d1397288a43b30d6b5e28a0068 %}

**isBoolean**

{% embed https://gist.github.com/K-Vishwak/fc38097d9757357cd5d46ca1c42e9f22 %}

**isString**

{% embed https://gist.github.com/K-Vishwak/5629b996c8c80ef4aa35baf1c1cf36d8 %}

**isObject**

{% embed https://gist.github.com/K-Vishwak/5e04a2280f1083a520fa1549bb8dc6a4 %}

**isArray**

{% embed https://gist.github.com/K-Vishwak/5e63f38433383cb962bf1c11edca2a17 %}

**isFunction**

{% embed https://gist.github.com/K-Vishwak/b51c2a02a6a0e1248ddb311c0358bd4f %}

**isInteger**
We can use `Number.isInteger(value)`

Yes. There are some exceptions based on where do we use these functions.

Please do suggest if I miss any mandatory validations in the above isFunctions.

Hope these help to a little extent instead of going over lengthy explanations around the globe 😝.

Thank you! Happy Reading :)

<hr style="border-width: 2px;border-color: #87CEEB;">
<h1> 💎 Love to see your response</h1>
<ol>
<li style="padding: 10px;font-size: 30px;"><b>Like</b> - You reached here means. I think, I deserve a like.  </li>
<li style="padding: 10px;font-size: 30px;"><b>Comment</b> - We can learn together. </li>
<li style="padding: 10px;font-size: 30px;"><b>Share</b> - Makes others also find this resource useful.</li>
<li style="padding: 10px;font-size: 30px;"><b>Subscribe / Follow</b> - to stay up to date with my daily articles. </li>
<li style="padding: 10px;font-size: 30px;"><b>Encourage me</b> - <a href="https://www.buymeacoffee.com/urstrulyvishwak" target="_blank">You can buy me a Coffee</a>
</ol>
<hr style="border-width: 2px;border-color: #87CEEB;">

<h2> Let's discuss further. </h2>

<ol style="padding: 20px;">
<li style="padding: 10px;font-size: 30px;">Just DM <br> <a href="https://twitter.com/messages/compose?recipient_id=1388837509824610314&text=Hello world"
class="twitter-dm-button" data-screen-name=“@urstrulyvishwak” data-size="large">@urstrulyvishwak</a>
</li>
<li style="padding: 10px;font-size: 30px;">
<p> Or mention <br> <a href="https://twitter.com/intent/tweet?screen_name=urstrulyvishwak&ref_src=twsrc^tfw" class="twitter-mention-button" data-size="large" data-text="Hi, Vishwak" data-related="@urstrulyvishwak" data-show-count="false">@urstrulyvishwak</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></p> </li>
</ol>

<h2> For further updates: </h2>
<a href="https://twitter.com/urstrulyvishwak?ref_src=twsrc^tfw" class="twitter-follow-button" data-size="large" data-text="Hi, Vishwak" data-related="@urstrulyvishwak" data-show-count="false">Follow @urstrulyvishwak</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>