DEV Community

Cover image for Understanding JavaScript at a deeper level: Primitive Types
Adonis 💲🏁
Adonis 💲🏁

Posted on

Understanding JavaScript at a deeper level: Primitive Types

In my opinion, 90% of things that you interact with in JavaScript would be considered a Primitive Type so understanding them and how they truly function would be great to have in your repertoire. At a basic level Primitive Types are very simple to understand, but that being said they do have some depth to them and understanding that depth can save you a few hours in debugging and trying to figure out why your code isn’t working in a way that you expected. There’s about 6 total Primitive Types; Booleans, Strings, Numbers, Null, Undefined, and Symbols. Each of the Types belong to their own respective classes and if you’re not aware of what classes are, overall their just rules for operation and each of them have built in functions that they can utilize in order to extend their functionality.

Let’s kick it off with one of the most important Primitive Types, Booleans. Booleans at their core are just true or false values. Determining whether something is true or false in Javascript or programming, in general, is extremely important; your entire logic is typically based behind if a value is true or false. Booleans also work hand in hand with another concept called comparisons and conditions which help tremendously when it comes to building logic gates in your code.

Next up in the Primitive Type lineup is Strings, they are a foundational concept in programming as well and might be the easiest of all of them to understand. Strings are just characters wrapped in quotes, nothing more, nothing less. Although Strings do have the power to covert other types into a String which can be very useful at times.

Numbers make the world go round and it only makes sense that JavaScript utilizes them. From simple algebra to finding the 145th power, the Numbers type can handle it all. Truth be told Numbers truly deserves it’s own article because they’re the most complex of all of the Primitive Types, so look out for that article coming soon!

The contract is Null and Undefined; Let’s say you had to guess exactly what the Null type is, 9/10 if you’re inexperienced you’d say something along the lines of expired or not valid, but that’s not actually the case with the Null type. Null is essentially saying that whatever you thought was there does not have a value, it’s null. However Undefined is extremely similar to Null but they have one key difference. Undefined is saying that the variable that you’re referencing doesn’t have a value yet.

The last and the newest JavaScript Primitive Type is Symbols. Symbols create unique and private key value pairs, which is similar to another JavaScript type, Objects. If you’re not aware of what Objects are just yet, don’t worry I’ll create another article going in detail of Objects, BUT for now just think of Objects like a container with references to information. What Symbols does is create private references that are not accessible in normal Object functions.

I hope that this article answered any questions that you may have had about JavaScript’s Primitive Types. However, if you didn’t have any questions I wrote this article in way that will give you some understanding even if you have zero knowledge about programming. As always if you have questions or comments please reach out and I’ll get back to you as quick as possible! Thank you.

Top comments (0)