EN
JavaScript - how check if a variable is a string or number?
0
points
In this article, we would like to show you how to check if a variable is a string or a number in JavaScript.
To check the type of variable we use typeof
operator.
Runnable example:
// ONLINE-RUNNER:browser;
let a = 1;
let b = 3.14;
console.log(typeof a);
console.log(typeof b);
Runnable example:
// ONLINE-RUNNER:browser;
let a = "text";
let b = 'text';
let c = `text`;
console.log(typeof a);
console.log(typeof b);
console.log(typeof c);