Variable Types

Since a variable can hold numerous data types, it is important to ensure that the value of a variable is the expected data type. In JavaScript, this can be done with the typeof operator or method. They both pretty much do the same thing but have syntax differences.

Typeof operator

let animalName = ‘Bongo’;
console.log( typeof animalName );

The console log should output string as the type of the variable “animalName”.

Typeof method

console.log( typeof( animalName ) );

Again, the console log should output string as the type of the variable “animalName”.

Happy Coding!

Clay Hess

More To Explore

Share This Post

small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.