0 day streak
javascript / beginner
Snippet

Checking Types with typeof

The typeof operator returns a string indicating the type of the operand, which helps in validating data.

snippet.js
javascript
1
2
3
4
const score = 100;
console.log(typeof score);
const isOnline = true;
console.log(typeof isOnline);
nodejs
Breakdown
1
typeof score
Evaluates to 'number' because the value is a numeric literal.
2
typeof isOnline
Evaluates to 'boolean' since the value is true or false.