JavaScript Data Types

CodingTute

JavaScript

A data type is a classification of values that determine how a value can be used and manipulated. JavaScript has several built-in data types, including:

  • Number: represents numeric values, including integers and floating-point numbers.
  • String: represents a sequence of characters, such as a word or phrase. Strings are written using single or double quotes.
  • Boolean: represents a logical value, either true or false.
  • Null: represents the absence of a value or a null value.
  • Undefined: represents the absence of a value or a value that has not been defined.
  • Object: represents a collection of key-value pairs, or a complex data structure.

Here are some examples of values of different data types in JavaScript:

var myNumber = 5;        // a number
var myString = "hello";  // a string
var myBoolean = true;    // a boolean
var myNull = null;       // null
var myUndefined;         // undefined
var myObject = {};       // an object

In addition to these built-in data types, JavaScript also supports arrays, which are special objects that can hold a collection of values. Arrays are written using square brackets and can contain values of any data type.

var myArray = [1, 2, 3, "four", true];  // an array

It’s important to note that in JavaScript, all values have a data type, even if it is not explicitly declared. The type of a value is determined automatically by the JavaScript runtime based on the value itself.

You can find the complete JavaScript Tutorials here.

Follow us on Facebook, YouTube, Instagram, and Twitter for more exciting content and the latest updates.

Exit mobile version