JavaScript Introduction

JavaScript Introduction

JavaScript: An Introduction to Data Types and their Usage

What is JavaScript?

JavaScript is a scripting language that is one of the three core languages used to develop websites. Whereas HTML and CSS give a website structure and style, JavaScript lets you add functionality and behaviors to your website, allowing your website’s visitors to interact with content in many imaginative ways.

JavaScript is primarily a client-side language, meaning it runs on your computer within your browser. However, more recently the introduction of Node.js has allowed JavaScript to also execute code on servers.

Values / Datatypes in Javascript

Data type specifies which kind of data is being stored in a variable and every variable has data type. There are two kinds of data types in javascript.

  • Primitive data types

  • Non-primitive data types

Primitive data types:

These are predefined data types in javascript that hold a single value. These are immutable, which means once the value is assigned it cannot be changed. There are seven primitive data types:

  1. Number: Represents numeric values, including integers and floating point numbers.

    let age = 25;
    let price = 98.5;

  2. String: Represents a sequence of characters that are surrounded by single quotes( ' ' ) or double quotes(" ").

    let name = "Dhiraj";
    let country = 'India';

  3. Boolean: Represents the logical value either true or false.

    let isStudent = true;
    let isLoggedIn = false;

  4. Undefined: The meaning of undefined is 'value is not assigned'. Variable without a value assigned.

    let data;

  5. Null: Represents the intentional absence of any object value. When you assign the value 'null' to a variable, you are essentially saying that the variable explicitly has no value or does not refer to any object.
    let data = null;

  6. Symbol: This data type is used to create objects which will always be unique. these objects can be created using Symbol constructor.
    const id = Symbol('unique identifier');

  7. BigInt: This data type can represent numbers greater than 253-1 which helps to perform operations on large numbers. The number is specified by writing ‘n’ at the end of the value.
    var bigNum = 123422222222222222222222222222222222222n

Non-Primitive data types:

These are derived from primitive data types also referred to as reference types, are more complex and can hold multiple values or a collection of values. They are mutable, meaning their values can be modified. There are two Non-Primitive data types:

  1. Object: It is a collection of key-value pairs enclosed in curly braces ({ }). An Object in Javascript is an entity having properties and methods. Everything is an object in javascript.
    const person = {name: 'John', age: '25'}

  2. Array: Using Array we can store more than one element under a single name. Arrays can store multiple values of any data type and are enclosed in square brackets ([ ]).
    const numbers = [1, 2, 3, 4, 5];

Did you find this article valuable?

Support Dhiraj Inchalkaranji by becoming a sponsor. Any amount is appreciated!