A Brief on Primitive JavaScript Data Types

T. J. Marstiller
1 min readMay 17, 2021

“JavaScript is a loosely typed and dynamic language. Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types:”

let foo = 42;    // foo is now a number
foo = 'bar'; // foo is now a string
foo = true; // foo is now a boolean

The above was quoted from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#dynamic_typing

Primitive Data Types

1. Numbers

A number is just that in Javascript. Whereas other languages such as Ruby or Python have “floats” that can be calculated easily, that is just not the case in JavaScript and things get weird quick. There are libraries out there to help you with this. One of them is “Numbers.js” https://github.com/sjkaliski/numbers.js/

2. Boolean

A simple true or false is a logical primitive data type.

3. Strings

In any programming language a set of characters used to represent text is called a String.

4. Undefined

An example of an “undefined” data type would be if you were to declare a variable and not assign a value to it.

These are the main Primitive Data Types that I have encountered during my JavaScript journey. There are others but so far they don’t seem to be something I encounter often.

For the best documentation about JavaScript please see the Mozilla docs at https://developer.mozilla.org/

Happy Hacking!

--

--