Sitemap
Jagan Chinnamuniraj

Jagan Chinnamuniraj

Frontend Developer | Mobile Apps | ReactJS | React Native | NextJS | JavaScript

JavaScript Data Types

2 min readDec 5, 2022
Press enter or click to view image in full size

JavaScript has a number of different data types that can be used to store and manipulate different kinds of information. These data types include:

  • number: Any numeric value, including integers and floating-point numbers.
  • string: A sequence of characters used to represent text.
  • boolean: A value that is either true or false.
  • null: A value that represents the absence of a value.
  • undefined: A value that indicates that a variable has not been assigned a value.
  • object: A collection of key-value pairs that can store any other data type, including other objects.
  • symbol: A unique identifier that is used to represent a value that cannot be changed or overwritten.

In addition to these data types, JavaScript also has a number of special values that are considered to be “falsy” or “truthy.” Falsy values include null, undefined, 0, and an empty string, while truthy values include any other value that is not falsy.

Get Jagan Chinnamuniraj’s stories in your inbox

Join Medium for free to get updates from this writer.

You can check the data type of a value in JavaScript using the typeof operator, which returns a string indicating the data type of the value. For example:

console.log(typeof 123); // "number"
console.log(typeof "Hello, world!"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof {}); // "object"

JavaScript is a dynamically-typed language, which means that you do not have to specify the data type of a variable when you declare it. The data type of a variable can change at any time, and the same variable can be used to store values of different data types.

For example, you can declare a variable x and assign it a number, then later reassign it to a string or any other data type:

let x = 123;
console.log(typeof x); // "number"

x = "Hello, world!";
console.log(typeof x); // "string"

Overall, understanding data types is important for working with JavaScript and for creating programs that can manipulate and store different kinds of information.

Overall, understanding data types is important for working with JavaScript and for creating programs that can manipulate and store different kinds of information.

--

--

Jagan Chinnamuniraj
Jagan Chinnamuniraj

Written by Jagan Chinnamuniraj

Frontend Developer | Mobile Apps | ReactJS | React Native | NextJS | JavaScript