Languages
[Edit]
EN

JavaScript - how check if a variable is a string or number?

0 points
Created by:
Aran-Busby
532

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);

Related posts

References

Alternative titles

  1. JavaScript - how check the type of a variable
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join