DEV Community

Cover image for What are some of JS' primitive data types?
Colby Cardell
Colby Cardell

Posted on

What are some of JS' primitive data types?

PRIMITIVE to me means BASIC! Like a caveman...and you literally cant build anything without basic data. primitive data type is data that is not an object and has no methods.

Some of the Primitive data types:

  • NUMBERS
  • STRING
  • BOOLEAN
  • UNDEFINED
  • NULL

Examples of Javascript numbers

100     //Integers
50
1.1     //Floats
100.69
Enter fullscreen mode Exit fullscreen mode

Examples of Javascript strings

"Hi!"     //you can define a 'string' by double quotes.
'Hi!'     //you can also define a 'string' by single quotes.
"30"     // this is also a string
Enter fullscreen mode Exit fullscreen mode

Examples of Javascript booleans

true  // Booleans only state is 'true' or 'false

false // It is either on or off, yes or no!!

Enter fullscreen mode Exit fullscreen mode

Examples of Javascript null & undefined

// null means that there is no value assigned..empty
// and is intentionally set
// undefined means that the container exists
// but hasnt been given a value

console.log(null === undefined);  //false
console.log(null == undefined);  // true

Enter fullscreen mode Exit fullscreen mode

Another day in the life using primitive data types in a loop

//while some number is less than 10, console.log('string type')

let i = 1;

// while something is true..run this scoped code
while (i < 10) {
  console.log('string type', i)

i += 1 // i = i + 1

}

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
codefinity profile image
Manav Misra

Good start.