Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

What is a Data Type?

A data type refers to the type of data such as text, numbers, and boolean values.


1. Number

Represents numeric values like integers, floats, and natural numbers.

Example:

Number Data Type
let age = 16;
let height = 170.5;

2. String

A string represents text information. It includes letters, words, or sentences enclosed in quotes (' ', " ").

Example:

String Data Type
let name = 'John';
let message = 'Hello!';

3. Boolean

The Boolean data type can have one of two values: true or false, similar to a switch being toggled on or off.

Example:

Boolean Data Type
let isStudent = true;
let hasDriverLicense = false;

4. Object

An object is a data type used to store collections of data. For example, a student object may contain the student's name, age, and grade.

Example:

Object Data Type
let student = {
name: 'John',
age: 16,
grade: 'Sophomore',
};

5. Array

An array is a list of values of the same type.

Array Data Type
let fruits = ['Apple', 'Banana', 'Grapes'];

6. Other Data Types

  • null

null is a special value that represents 'no value'. It is used to explicitly signify that a variable has no value assigned.

Example:

null Data Type
let emptyValue = null;

  • undefined

undefined is a value assigned to variables that have been declared but not yet assigned a value. It indicates that a variable has not been defined with a value. If you declare a variable and do not initialize it, JavaScript automatically assigns it the value undefined.

Example:

undefined Data Type
let notDefinedYet;
console.log(notDefinedYet); // Output: undefined
  • Both null and undefined signify the absence of value, but they are used in different contexts and have different meanings. null is used to explicitly state the absence of a value, whereas undefined indicates that a variable has been declared but not yet assigned a value.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.