Learn Javascript Data Types

When you start to learn javascript, one term will come in front of you. It’s the data type. Without learning this you can move forward. Because it’s a fundamental thing.

Here we discuss data types. So, what is data type?

Well. Actually, type is an attribute of data that tells the compiler or interpreter for what purpose you are using data.

The latest ECMAScript defines nine types of data. Let’s learn one by one.

First, we will know about the primitive data types. Take a look at primitive data type.

  1. Undefined
  2. Null
  3. Boolean
  4. Number
  5. String
  6. Symbol
  7. BigInts

Let’s figure out one by one primitive data type.

  1. Undefined

Undefined is a primitive value that assigned to a variable automatically which only declared but nothing in it.

var a; // variable declearation with no valueconsole.log(a); // Output: undefinned

2. Null

Null means nothing but something. It's like an empty pot. There is nothing but we will fill it in later. That’s it.

var a = null;
console.log(a) // Output: null

3. Boolean

Booleans are the logical data type. It has two values. One is true and another is false It is used to make decisions.

if(true){
console.log('It is done');
} else {
console.log('It is undone')
}
// Output: It is done

4. Number

Numbers are the numeric data type. Basically, it has integer and float. Positive or negative or nonnegative everything is in number data type.

var a = 10;
var b = -10;
var c = 0;
console.log(a); // Output: 10
console.log(b); // Output: -10
console.log(c); // Output: 0

5. String

When we want to write text, we can do it in javascript. That is the string. Anything we want to write is string. Every string must between a single quote or double quote.

var a = 'This is my blog';
var b = "This is my blog";
console.lgo(a); // Output: This is my blog
console.lgo(b); // Output: This is my blog

6. Symbol

Symbol is an uncommon data type. It is included on ES5. Every time it produces a unique value. It can have same description for more than one Symbol but all of them are unique. Let’s try a example.

var a = Symbol('Blog');
var b= Symbol('Blog');
console.log(a === b); // Output: false

7. BigInts

Generally it numeric data type. But it can be used for big numeric value.

All these are primitive data type. Now let’s talk about objects and function.

Objects

Basically, everything is object. If you see a car, it is object. If you see a tree it is object. Object can be written in curly braces {}

Function

In simple word, functions are a collection of commands that we use many times in our code. Every function can accept any number of arguments. With the arguments a function can be used dynamically. But every time they must done same type of work. Their data may be different but type of work will be the same. Let’s try a function example.

function square(n){
console.log(n*n);
}
square(2); // Output: 4
square(3); // Output: 9
square(4); // Output: 16

We can call as many times as we want. Function can return values so that we may use it later.

function square(n){
return(n*n);
}
const two = square(2); // It will reserve the value in the variable
console.log(two) // Output 4
const three = square(3); //It will reserve the value in the variable
console.log(three) // Output 9
const four = square(4); // It will reserve the value in the variable
console.log(four) // Output 16

All these are data types. Now we will talk about a method that is used to find type of data.

TypeOf()

Suppose we don’t know what is the data type of it. Or we are curious to varify the type of data. Then we can easily find the type of data with this method.

console.log(typeOf(undefined)); // Output: undefined
console.log(typeOf(null)); // Output: null
console.log(typeOf(10)); // Output: number
console.log(typeOf('Good day')); // Output: Good day
console.log(typeOf({})); // Output: object

That’s all for today. Thank you for reading.

--

--

--

Web Designer at VoicePro LLC

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Web scraping with JavaScript and Node.js

Javascript Fundamentals: Functions

Why Should We Use Reactive Programming In Angular?

The stunning features of Nodejs

SPECIAL FEATURES OF NODEJS(UPDATED)

Functional Programming and Function Chaining in JavaScript

React dropzone upload multiple images to firebase storage(all articles)

Building a Scroll Spy Using Angular 9 and ngx-perfect-scrollbar

Micro-Interactions: Digital Expressions

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Asif Jalil

Asif Jalil

Web Designer at VoicePro LLC

More from Medium

Learning JavaScript Must know these things

Longest Substring with K Distinct Characters

ReactJS And AngularJS: Which One To Choose In 2022!

ReactJS vs AngularJS — Verzeo

How To build a JavaScript Tic-Tac-Toe Game With Colors