xxxxxxxxxx
Non-primitive data types in JavaScript includes:
Objects
Arrays
xxxxxxxxxx
//primitive = {STRING, NUMBER, BOOLEAN, SYMBBOL, UNDEFIEND, NULL}
//non-primitive = {ARRAY, OBJECT, FUNCTION}
//primitive is always copied by VALUE
var a = 1;
var b = a;
//console.log(a , b) = 1 , 1
a = 3;
console.log(a) //3
console.log(b) // still 1 and not 3 (always copied by value only)
//non-primitive is always copied by REFERENCE
var x = {name : "Jscript"};
var y = x;
//console.log(x , y) TWICE = Object { name: "Jscript" }
x.name = "Js";
console.log(x) //Js
console.log(y) //Js {copied by reference} like pointers in C lang
xxxxxxxxxx
/*
boolean.
bigint.
null.
number.
string.
symbol.
undefined.
*/
best way to remember is BBNNSSU
xxxxxxxxxx
- String : text data
- Number : numeric data
- Boolean : `true` or `false`
- Null : intentional absence of value (`void` in some other language)
- Undefined : absence of value due to not yet being initialized
- BigInt : Very big numeric value
- Symbol : Works as a unique identifier
xxxxxxxxxx
Primitive Data Types
Primitive data types in JavaScript include:
Numbers - Integers, floats
Strings - Any data under single quote, double quote or backtick quote
Booleans - true or false value
Null - empty value or no value
Undefined - a declared variable without a value
Symbol - A unique value that can be generated by Symbol constructor
xxxxxxxxxx
Quas : WHAT IS JAVASCRIPT PRIMITIVE AND NON PRIMITIVE DATA TYPE ?
Ans :
primitive =>
STRING => var myName = 'iqbal';
NUMBER => var myAge = 25;
BOOLEAN => var iAmStudent = true;
symbol => +, -, *, /, % +=, -=, ++, --, <, >, =, ==, ===, !==, !=, <=, >=
undefined => A variable that has not been assigned a value of your code
null => Null means having no value
non-primitive =>
ARRAY =>
var friendsName = ['habib', 'iqbal', 'shorif', 'asraful', 'rasel', 'arif', 'deader' ];
OBJECT =>
var mobile = {
brand : 'iPhone',
price : 79000,
storage : '64gb',
camera : '50MP'
}
FUNCTION =>
function isEven(number){
const remainder = number % 2;
if(remainder === 0){
return true;
}
else{
return false;
}
}
const evEnNumber = 180;
const evenNumber2 = 185;
const toTalEven = isEven(evEnNumber);
const totalEven2 = isEven(evenNumber2);
console.log(toTalEven);
console.log(totalEven2);
xxxxxxxxxx
"I am a sentence" // this is a string of text, or string, delimited by double-quotes.
'I am also a sentence' // another string, in this case using single-quotes. In JavaScript single and double-quotes work the same, but you can not use both forms on the same string.
53 // this is a number. Whole numbers are commonly called integers, but they are still of type number in JavaScript.
12.34 // another number. Numbers with a decimal point are often called floating-point numbers.
true // this is a Boolean. Booleans are either true or false.
false // another Boolean.
xxxxxxxxxx
undefined // this is a special value and also a type, which signifies a complete absence of a value. If a value is not given, the system defaults to undefined.
null // another special value to signify absence. Null is used to say that the developer specifically wants this value to be absent.
NaN // "Not A Number", a value that represents things like zero divided by zero.