Know the type of Variable in JS!
Lenin Felix
Posted on April 30, 2021
Many times (...I guess) you have wanted or tried to want to know what type is a variable, and most likely you know it since 98% of the times you are the one who declares them.
But imagine to find yourself with an API or a third party code which you have to manipulate, that already becomes more complex, since you are only there to use that little world of variables, functions, texts and others...
Although also many times it is useful to know what type are the variables in order to create conditionals that are prepared to manipulate and to maintain your code stable and that it does not crack your code of "Hello World".
For that reason I offer you a small example of functions that you can use for those occasions (I know that it is little, but it is honest work).
Basically, these are functions to which you pass your variable to indicate whether it is of a certain type or not.
It can work, for example, in some function in which you pass parameters, but you have to do different things if the parameter receives an Object or an Array.
At first sight it could not seem very useful, but at least to me, with certain code that I had to make, it helped me.
If you liked the content you can follow me on my social networks as @soyleninjs
Posted on April 30, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.