What is Data Type in JS

In JavaScript, data types refer to the classifications of values that determine the operations that can be performed on them and the way they are stored in memory. JavaScript has several built-in data types, which can be categorized into two main categories: primitive types and reference types.




Primitive types:


Number: Represents numeric values, including integers and floating-point numbers. For example: 3, 3.14.


String: Represents a sequence of characters enclosed in single or double quotes. For example: 'hello', "world".


Boolean: Represents a logical value, either true or false.


Null: Represents the intentional absence of any object value. It is a special value denoting the absence of an object reference.


Undefined: Represents an uninitialized variable or an object property that does not exist.


Symbol: Represents a unique identifier and is often used as a key in JavaScript objects. Symbols are introduced in ECMAScript 2015 (ES6) and are created using the Symbol() function.




Reference types: 



Object: Represents a collection of key-value pairs and is a fundamental construct in JavaScript. Objects can be created using object literals ({}) or the new keyword with constructors.


Array: Represents an ordered collection of values. Arrays can hold elements of any data type, and they are created using square brackets ([]).


Function: Represents a reusable block of code that can be invoked by its name. Functions are created using the function keyword or by using arrow function syntax (() => {}).


Date: Represents a specific moment in time, including various methods for manipulating dates and times.


RegExp: Represents a regular expression, which is used for pattern matching and manipulation of strings.


...and others: JavaScript also provides additional built-in reference types like Map, Set, Promise, etc., introduced in later ECMAScript versions.




JavaScript is a dynamically typed language, meaning you don't need to explicitly declare the data type of a variable. The data type is determined automatically based on the value assigned to the variable.

SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment