DEV Community

Ranjith srt
Ranjith srt

Posted on • Edited on

Js | DataTypes |



Datatypes 


Enter fullscreen mode Exit fullscreen mode
  • Javascript is Dynamic Typing

  • Primitive and Object Type



Primitive Data Types:


Enter fullscreen mode Exit fullscreen mode

1.Number - Represents both integer and floating-point numbers.




let age=10;  #equal two apram enna num,str,bool ex...automatic convert pannikum enna datatype nu.
console.log(age);
console.log(typeof age); 

output:
10
number



Enter fullscreen mode Exit fullscreen mode



age="25";
console.log(age);
console.log(typeof age); 

output:
string



Enter fullscreen mode Exit fullscreen mode

float number:




let price=19.99;
console.log(price);
console.log(typeof price); 

output:
19.999
number



Enter fullscreen mode Exit fullscreen mode

2.String - Represents a sequence of characters.




let greeting="Hello World.!"
console.log(greeting);
console.log(typeof greeting); 

output:
string



Enter fullscreen mode Exit fullscreen mode

3.Boolean - Represents a logical entity and can have two values: true or false.




let isActive=true;
console.log( isActive);
console.log(typeof  isActive);



Enter fullscreen mode Exit fullscreen mode



let isActive=false;
console.log( isActive);
console.log(typeof  isActive); 



Enter fullscreen mode Exit fullscreen mode

4.Undefined - A variable that has been declared but not assigned a value.




let name;  #Error undefined
console.log( a);
console.log(typeof a); 



Enter fullscreen mode Exit fullscreen mode

5.Null - Represents the intentional absence of any object value.




let name = null:
console.log(name);
console.log(typeof name); 



Enter fullscreen mode Exit fullscreen mode

6.Symbol - Represents a unique and immutable value, often used as object property keys.




let unique=symbol("key"); #custom symbol
console.log(unique);
console.log(typeof unique); 

output:
symbol("key")



Enter fullscreen mode Exit fullscreen mode

7.BigInt - Represents whole numbers larger than 2^53 - 1 (the largest number JavaScript can reliably represent with the Number type).




let largeNumber=BigInt(68690356789000833);



Enter fullscreen mode Exit fullscreen mode



let largeNumber=68690356789000833n; #using the n notation

console.log( largeNumber);
console.log(typeof largeNumber); 

output:
68690356789000833n



Enter fullscreen mode Exit fullscreen mode



Non-Primitive Data Types 



Enter fullscreen mode Exit fullscreen mode

1.Object

Represents a collection of properties, each consisting of a key (usually a string)
and a value (which can be any data type, including another object.




let person={

  name-'ranjith'.
  age=25,
  isEmployed=true;
}

console.log( person); //total laa print agum
console.log( person .name);  // name only
console.log( person .age);  // age only
console.log( person .isEmployed);

console.log(typeof  person); 



Enter fullscreen mode Exit fullscreen mode

2.Array

A special type of object used for storing ordered collections of values.




let number=[1,2,5,4,8];
console.log( number);

let mixdata=[1,'2',true,false,null,[1,2,'5',"str"] ,undefined ];
console.log( mixdata);



Enter fullscreen mode Exit fullscreen mode

3.Function

A special type of object that is callable and can perform an action.




function invite( ){
   console.log( "you are invitd");
}
invite()



Enter fullscreen mode Exit fullscreen mode

4.Date - A built-in object for handling dates and times.




let now = new Date;
console.log( now);

outut:
date wed jul 24 2024 09.00:51 Gmt( indian stamdard)



Enter fullscreen mode Exit fullscreen mode

Top comments (0)