What are Data-types?
What are Data-types?
The values which we assign to the variables are of a specific type which is called the data type of that specific variable. We can assign numbers, string, boolean, null, undefined, array, object, functions, and symbols to variables.
Introduction to different Data-types
Following is a brief introduction to the commonly used data types in JavaScript. We will go through these in detail in the upcoming chapters, but for now, letβs just get a basic understanding of all these.
- Number
Numbers are always floating-point numbers so both the integers as well as floating-point numbers are simply numbers in JavaScript.
12let totalCoins=100; console.log(totalCoins)
- BigInt:
BigIntis used to represent numbers of arbitrary lengths. ABigIntnumber can be generated by appendingnat the end of a number.
123// the "n" at the end means it's a BigInt const bigInt = 12345678901234567890123n; console.log(bigInt);
Strings:
We use quotes to represent the strings. They are commonly used to deal with text.
12let comment="good"; console.log(comment);
- Boolean (logical type):
In this type, we have only two values:
trueandfalse. We usetruefor βYesβ, andfalseis used for βNoβ. For instance, if we want to store the value of "It's raining" we will set the value totrueand if it is not raining then we will set the valuefalse.
12let isRaining = true; console.log(isRaining);
- null:
The
nullis a special value that represents βnothingβ, βemptyβ, or βvalue unknownβ.
12let selectedColor = null; console.log(selectedColor)
- Undefined:
In JavaScript, a default value of
undefinedis assigned to the variable if we do not assign a value to it.
12let age; console.log(age);
The typeof Operator:
The typeof operator is used to get the type of the value or variable. Itβs useful to quickly check the types of values that are assigned to the variable.
To check the type we use the typeof keyword and pass the variable inside parentheses.
12let drink="soda"; console.log('typeof("drink"):', typeof(drink));
Swipe to start coding
Check the type of the following variable and display it on the console.
Solution
Thanks for your feedback!
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you explain the difference between null and undefined in JavaScript?
What are some examples of when to use each data type?
How does the typeof operator behave with different data types?
Awesome!
Completion rate improved to 2
What are Data-types?
Swipe to show menu
What are Data-types?
The values which we assign to the variables are of a specific type which is called the data type of that specific variable. We can assign numbers, string, boolean, null, undefined, array, object, functions, and symbols to variables.
Introduction to different Data-types
Following is a brief introduction to the commonly used data types in JavaScript. We will go through these in detail in the upcoming chapters, but for now, letβs just get a basic understanding of all these.
- Number
Numbers are always floating-point numbers so both the integers as well as floating-point numbers are simply numbers in JavaScript.
12let totalCoins=100; console.log(totalCoins)
- BigInt:
BigIntis used to represent numbers of arbitrary lengths. ABigIntnumber can be generated by appendingnat the end of a number.
123// the "n" at the end means it's a BigInt const bigInt = 12345678901234567890123n; console.log(bigInt);
Strings:
We use quotes to represent the strings. They are commonly used to deal with text.
12let comment="good"; console.log(comment);
- Boolean (logical type):
In this type, we have only two values:
trueandfalse. We usetruefor βYesβ, andfalseis used for βNoβ. For instance, if we want to store the value of "It's raining" we will set the value totrueand if it is not raining then we will set the valuefalse.
12let isRaining = true; console.log(isRaining);
- null:
The
nullis a special value that represents βnothingβ, βemptyβ, or βvalue unknownβ.
12let selectedColor = null; console.log(selectedColor)
- Undefined:
In JavaScript, a default value of
undefinedis assigned to the variable if we do not assign a value to it.
12let age; console.log(age);
The typeof Operator:
The typeof operator is used to get the type of the value or variable. Itβs useful to quickly check the types of values that are assigned to the variable.
To check the type we use the typeof keyword and pass the variable inside parentheses.
12let drink="soda"; console.log('typeof("drink"):', typeof(drink));
Swipe to start coding
Check the type of the following variable and display it on the console.
Solution
Thanks for your feedback!
single