Forem

Santhosh Kumar
Santhosh Kumar

Posted on

1 1

JAVASCRIPT: DATA TYPES

This post was originally published on my blog, find original post here

Every variable has a data type that determines type of value it stores, a variable of type number can store an integer or floating-point numbers.

JavaScript is dynamically typed language which means a variable can be number type for a moment and at another be a string type.

Number

number type represents both integer and fractional (floating point numbers).

let num = 79; // integer
let num = 65.45; // floating-point

We can perform arithmetic operations like +, -, *, /.

let num = 45 + 2 * 6; // 57

For very big number or very small number, we can use e (exponent)

let speedOfLight = 2.998e8;

Infinity represents mathematical infinity, this is a special numeric value.

let infinity = 1 / 0; 
console.log(infinity); // Infinity

NaN is also a special numeric value to represent the incorrect or invalid mathematical operation.

let nan = "str" / 79;

We can get the data type of a variable using typeof.

console.log(typeof "peace"); //string

String

string is used to represent text. They are written by eclosing them their content in quotes.

let hello = "Hello World";
let sq = 'sinle quote';

Both single quote and double quote can be used.

Backticks represents string template, we can embed variable and expression in a string by enclosing them in ${ variable or expression }
expression inside ${....} is evaluated and becomes a part of the string.

let name = "Kevin";
console.log(`My name is ${ name } `); // My name is kevin
console.log(`Age is ${17 + 1} `); // Age is 18

Boolean

Boolean type has two values only: true and false.

It is used to store yes/ no values.

let isGreater = true;

null

To represent nothingness, empty, we can use null

let answer = null;

undefined

if a value is not assigned to a variable or variable is not declared , it will have undefined .

Meaning of undefined is "value is not assigned".

let a;
console.log(a) //undefined

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

đź‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay