Languages
[Edit]
EN

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

0 points
Created by:
Dirask Community
6900

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

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