DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for What Are JavaScript Data Types?
Okanu Gracious
Okanu Gracious

Posted on

What Are JavaScript Data Types?

Data Types specify the kind of data stored and manipulated in a program.

Data Types can be categorized into six parts which isn’t divided into three main categories.....

1. Primitive:
<>Number
<>String
<>Boolean

2. Compound:
<>Array
<>Object
<>Function

3. Undefined:
<>Undefined

The two most common categories are know to be different from each other because primitive data Types can only contain one value simultaneously while the compound data Types can contain more values.
Let’s explain them accordingly...

<>String Data Type<>:
This data type deals with textual values and characters which are created with the double or single quotation mark on the keyboard. Example...

var a = β€œhi there”;
var b = β€œhello there”;
Enter fullscreen mode Exit fullscreen mode

<>Number Data Type<>:
This data type deals with positive and negative numbers without or with decimal numbers and places written using exponential quotations.

Example....

var c = 24;
var d = 23.7;
Enter fullscreen mode Exit fullscreen mode

Note: When writing codes for Number Data Types, strings are not supported in other To bring a desired outcome.

<>Boolean Data Type<>:
The Boolean Data Type can only contain two values: TRUE or FALSE.
It is usually used to show values like Yes(true) or No(false). For example....

var Show = true;
var IsShow = false;
Enter fullscreen mode Exit fullscreen mode

<>Undefined Data Type<>:
This data type is can be used to assign a single value: The Undefined Special Value.
This data type is effective when you declare a variable without a value.
For example....

var d;
var e = β€œOkanu Gracious”;

alert(d) // Output: Undefined
alert(e) // Output: Okanu Gracious

Enter fullscreen mode Exit fullscreen mode

<>Object Data Type<>:
The object Data type is a very complex data type in JavaScript which has one sole aim. The aim of the object data type is to store large collections of data.
An example of Object Data Type are....

var WebDev = {
Frontend : β€œHTML and CSS”
Backend : β€œMySQL and Python”
}
Enter fullscreen mode Exit fullscreen mode

<>Array Data Type<>:
An array data type is a type of data type where a programmer inputs different data values in a single variable. An example of Array data type includes....

var Frontend = [β€œHTML”, β€œCSS”, β€œJavaScript”, β€œReactJS”, β€œVue”]

alert(Frontend[0]); // Output: HTMl
Enter fullscreen mode Exit fullscreen mode

<>Function Data Type<>:
This is data type which executes a block of codes. Functions can be used anywhere, it can be stored in an array, objects, variables, anywhere.
An example of Function Data Type are...

function Myfunction(){
console.log(β€œhello”)
}
Enter fullscreen mode Exit fullscreen mode

Thank you for reading!
Do follow me on Twitter @okanugracious

Top comments (3)

Collapse
lukeshiru profile image
Luke Shiru

A few corrections:

  • In Primitive you're missing symbol, bigint, null and undefined. You can learn more about them here.
  • There aren't any "compound" data types, there are just primitives and objects. Array and Function are objects. The only difference is that functions are objects that can be called. You can learn more about that here.
  • undefined is not it's own data type, is a primitive.

Cheers!

Collapse
graciousdev profile image
Okanu Gracious Author

Thank you sir.
I’m still a beginner

Collapse
lukeshiru profile image
Luke Shiru

That's ok! More the reason to share this corrections with you! Hope they help! ☺️

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.