Thursday, June 7, 2018

JavaScript - How to find the datatype of a variable in JavaScript

Observe the following code:

var variable1 =5;
console.log(typeof variable1);

// Console Output:
"number"


Here, the typeof operator returns a string informing us the datatype of the variable.

Reference:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof

No comments:

Post a Comment