Update 02_day_data_types.md

pull/260/head
Subrat Kumar Das 3 years ago committed by GitHub
parent 97f84bf65f
commit 717ae46eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -72,20 +72,29 @@ Non-primitive data types in JavaScript includes:
Now, let us see what exactly primitive and non-primitive data types mean. Now, let us see what exactly primitive and non-primitive data types mean.
*Primitive* data types are immutable(non-modifiable) data types. Once a primitive data type is created we cannot modify it. *Primitive* data types are immutable(non-modifiable) data types. Once a primitive data type is created we cannot modify it.
It may be little bit confusing for beginner learners. Do not confuse with primitive data and a variable assigned a primitive data. We can assign a new primitive value to the variable. All i want to say is that non primitive datas can be altered but not primitive. Let us have a look at the below example :
**Example:** **Example:**
```js ```js
let word = 'JavaScript' let word = 'JavaScript'
``` console.log(word) // JavaScript
word.toUpperCase() // this is a string method to convert it to upper case
If we try to modify the string stored in variable *word*, JavaScript should raise an error. Any data type under a single quote, double quote, or backtick quote is a string data type. console.log(word) // JavaScript (still we are getting the same result because it is a primitive data type)
// If we want to change it then we have to reassign it with new data type
word = word.toUpperCase()
console.log(word) // JAVASCRIPT
```js // Now letus use a method in non-primitive data type
word[0] = 'Y' let x = []; // creates an array variable
console.log(x); // []
x.push("Subrat");
console.log(x); // ["Subrat"]
``` ```
This expression does not change the string stored in the variable *word*. So, we can say that strings are not modifiable or in other words immutable. Remember, Any data type under a single quote, double quote, or backtick quote is a string data type.
Primitive data types are compared by its values. Let us compare different data values. See the example below:
Primitive data types can be compared by its values. Let us compare different data values. See the example below:
```js ```js
let numOne = 3 let numOne = 3

Loading…
Cancel
Save