Course Content
Introduction to JavaScript (staging)
Introduction to JavaScript (staging)
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.
let totalCoins=100; console.log(totalCoins)
- BigInt:
BigInt
is used to represent numbers of arbitrary lengths. ABigInt
number can be generated by appendingn
at the end of a number.
// 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.
let comment="good"; console.log(comment);
- Boolean (logical type):
In this type, we have only two values:
true
andfalse
. We usetrue
for “Yes”, andfalse
is used for “No”. For instance, if we want to store the value of "It's raining" we will set the value totrue
and if it is not raining then we will set the valuefalse
.
let isRaining = true; console.log(isRaining);
- null:
The
null
is a special value that represents “nothing”, “empty”, or “value unknown”.
let selectedColor = null; console.log(selectedColor)
- Undefined:
In JavaScript, a default value of
undefined
is assigned to the variable if we do not assign a value to it.
let 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.
let drink="soda"; console.log('typeof("drink"):', typeof(drink));
Swipe to show code editor
Check the type of the following variable and display it on the console.
Thanks for your feedback!
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.
let totalCoins=100; console.log(totalCoins)
- BigInt:
BigInt
is used to represent numbers of arbitrary lengths. ABigInt
number can be generated by appendingn
at the end of a number.
// 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.
let comment="good"; console.log(comment);
- Boolean (logical type):
In this type, we have only two values:
true
andfalse
. We usetrue
for “Yes”, andfalse
is used for “No”. For instance, if we want to store the value of "It's raining" we will set the value totrue
and if it is not raining then we will set the valuefalse
.
let isRaining = true; console.log(isRaining);
- null:
The
null
is a special value that represents “nothing”, “empty”, or “value unknown”.
let selectedColor = null; console.log(selectedColor)
- Undefined:
In JavaScript, a default value of
undefined
is assigned to the variable if we do not assign a value to it.
let 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.
let drink="soda"; console.log('typeof("drink"):', typeof(drink));
Swipe to show code editor
Check the type of the following variable and display it on the console.
Thanks for your feedback!