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.
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Tiivistä tämä luku
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 2
What are Data-types?
Pyyhkäise näyttääksesi valikon
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.
Ratkaisu
Kiitos palautteestasi!
single