Datatypes in javascript

You are currently viewing Datatypes in javascript

Datatypes in javascript

JavaScript provides different data types to hold different types of values. Understanding data types is essential because they determine how data is stored, how operations are performed, and how values are treated in our JavaScript code. JavaScript has several built-in data types, which can be categorized into two main groups: primitive data types and Non-primitive (reference) data type.
JavaScript is a dynamic type language, means we don’t need to specify type of the variable because it is dynamically used by JavaScript engine. we need to use ‘var’ here to specify the data type. It can hold any type of values such as numbers, strings etc. For example:

				
					var a=41;  //holding number  
var name="Vishal";  //holding string  

				
			

1) Primitive Data Types

The predefined data types provided by JavaScript language are known as primitive data types. Primitive data types are also known as in-built data types.

  • String: JavaScript Strings are similar to sentences. They are made up of a list of characters, which is essentially just an “array of characters, like “Hello World” etc.
  • Number: Represents both integers and floating-point numbers. For example, 3, 3.14, and -42 are numbers.
  • Boolean: Represent a logical entity and can have two values: true or false.
  • Null: This type has only one value that is null.
  • Undefined: A variable that has not been assigned a value is undefined.

2) Non-Primitive Data Types

The data types that are derived from primitive data types of the JavaScript language are known as non-primitive data types. It is also known as derived data types or reference data types.

  • Object: Represents a collection of key-value pairs, where the keys are strings (or Symbols) and the values can be of any data type.
  • Array: array is an object that represents a collection of similar type of elements.
  • RegExp: Represents regular expressions, used for pattern matching and text manipulation.

Leave a Reply