Exploring the Various Data Types in JavaScript: From Primitives to Objects


Data types in JavaScript describe the different types or kinds of data that you will be working with and storing in variables. It's important that you learn each of these data types because otherwise data can get stored in an improper format which will result in issues in your code later on.n JavaScript, data types are used to classify different types of data and define the type of values that a variable can hold. The main data types in JavaScript include:

Primitive data types: These are the basic data types that include numbers, strings, booleans, and special values like null and undefined.

Data Type Description
String A string is a collection of alphanumeric characters.
Number Numbers are for numbers. We can't put a letter on here.
Boolean Booleans have two values. True and false.
Null and Undefined null and undefined stand for empty. That means they have no value assigned to them.
Symbols Symbol is a primitive data type of JavaScript.It's a very peculiar data type. Once you create a symbol, its value is kept private and for internal use.
Array An array is a type of object used for storing multiple values in single variable.
Object Literals It is a comma-separated list of name-value pairs wrapped in curly braces.
Date JavaScript does not have a date data type. However, you can use the Date object and its methods to work with dates and times in your applications.

JavaScript is a loosely typed language, which means that the data type of a variable does not have to be explicitly declared. Instead, JavaScript automatically determines the data type of a variable based on the value assigned to it. However, it's a good practice to be aware of the data types in JavaScript as you work with variables and write your code.

In addition to these basic data types, JavaScript also has some special data types like Symbol and bigInt, which are used for specific purposes.

Source Code

HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tutor Joes</title>
</head>
<body>
 
	<script src="js/script.js"></script>
</body>
</html>
To download raw file Click Here

script.js
//Data Types in JavaScript
/*
JS Dynamic Programming
 
String
Number   eg:  1.25,25
Boolean  eg:  True,False
Null
Undefinded 
Symbols  E6
 
 
Array
Object Literals
Date
*/
 
var a=25.5;
var fname="Tutor Joes";
var isMarried=true;
var phone=null;
let b;
console.log(typeof b);
 
 
//ES6 2015
 
const s1=Symbol() //dlkfngsgs6565df6
console.log(s1)
 
const s2=Symbol() //fdfgdfg4345345
console.log(s2)
 
console.log(s1==s2);
 
 
var courses=['C','C++','Java'];
var student={
  'name':'Joes',
  'age':22
}
var d=new Date();
console.log(d);
console.log(typeof d);
To download raw file Click Here

List of Programs


JS Practical Questions & Answers


JS Practical Project