Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Data Types

JS Data Types

JavaScript provides different Data Types to store different types of value in a variable.

JavaScript is a Dynamic Type Language, means you don't need to specify type of the variable because it is dynamically used by JavaScript.

					 
        
          var demo;  // demo is undefined

          demo = 10;  // demo is number

          demo = "Lynxsia IT Solutions";  // demo is string

          demo = true;  // demo is Boolean
        
      
Dynamic Type Casting

JavaScript changes data type of the variable as per the calculation.

					 
        
          var a = 10;
          var b = "Lynxsia";
          var c = a + b;  // Here a is dynamically casted to string
        
      
Different types of Data
Primitive Data Types
  • Numbers
  • String
  • Boolean
  • Null
  • Undefined
Non Primitive Data Types
  • Objects
  • Array
  • Dates
JavaScript Numbers

All JavaScript numbers are stored as decimal numbers (floating point).

					 
        
          // Float (With decimals)
          let a = 34.00;

          // Integer (Without decimals)
          let b = 34;

          // Big Integer
          let x = BigInt("123456789012345678901234567890");

          // Big Integer
          let y = 123e5;    // 12300000
          let z = 123e-5;   // 0.00123
        
      
JavaScript String

A string (or a text string) is a series of characters. Strings are written with quotes. You can use single or double quotes.

					 
        
          // Single quote inside double quotes:
          let answer1 = "It's alright";

          // Single quotes inside double quotes:
          let answer2 = "He is called 'Johnny'";

          // Double quotes inside single quotes:
          let answer3 = 'He is called "Johnny"';
        
      
JavaScript Booleans

Booleans can only have two values: true or false.

					 
        
          let a = true;
          let b = false;
        
      
JavaScript Arrays

JavaScript arrays are written with square brackets. Array items are separated by commas. The following code declares (creates) an array called cars, containing three items (car names). Array indexes are zero-based, which means the first item is [0], second is [1], and so on.

					 
        
          const cars = ["Saab", "Volvo", "BMW"];
        
      
JavaScript Objects

JavaScript objects are written with curly braces {}. Object properties are written as name:value pairs, separated by commas.

					 
        
          const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved