JS Using typeof to check on string types

you can use the typeof operator to check what kind of variables you have.

HTML

<!-- console log result -->
(index):190 var_one is a : number with the value 1
(index):191 var_two is a : string with the value 1
(index):192 var_three is a : boolean with the value true
(index):193 var_four is a : boolean with the value true

Javascript

var var_one = 1;
var var_two = '1';
var_three = true;
var_four = !!1;

console.log("var_one is a : " + typeof var_one + " with the value " + var_one);
console.log("var_two is a : " + typeof var_two + " with the value " + var_two);
console.log("var_three is a : " + typeof var_three + " with the value " + var_three);
console.log("var_four is a : " + typeof var_four + " with the value " + var_four);

Demo

(index):190 var_one is a : number with the value 1 (index):191 var_two is a : string with the value 1 (index):192 var_three is a : boolean with the value true (index):193 var_four is a : boolean with the value true
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹