#100DaysOfVanillaJS: What is JavaScript, Primitive Data Types & Let, Var and Const
Tags: webdev, javascript, beginners, programming
Published: 2020-04-08 12:17:21

---
title: #100DaysOfVanillaJS: What is JavaScript, Primitive Data Types & Let, Var and Const
published: true
series: #100DaysOfVanillaJS
description: My attempt at explaining JavaScript in a chill, relatable way. No libraries or frameworks included
tags: webdev, Javascript, beginners, programming 
canonical_url: https://taeluralexis.com/2020/04/22/100daysofvanillajs-what-is-javascript-primitive-data-types-let-var-and-const/
---
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/764lv5910ojc3tmd3l7u.jpg)
<blockquote>Sailor Moon learning how to code :p </blockquote>
## Why Did I Create The #100DaysofVanillaJS Series?
<em>(This a completely optional part of the tutorial, feel free to skip it!)</em>

The series serves as my attempt at explaining JavaScript the best way I can. It took failing, building and having to work with it in day-to-day situations to truly begin to not only understand it, but appreciate it for what it is and what it can do.

My goal for the series to not only introduce you to the fundamentals of the programming language, but also explain how JavaScript works under the hood without any frameworks or libraries. This will be an ongoing and ever-evolving series as JavaScript will continue to come out with more features. I also seek to deepen my own knowledge of the language and this is a great way to better my technical communication abilities.

My aim is to make this series digestible and easy for everyone to understand, whether you’re a complete beginner to coding or prepping for those all too intense technical interviews. 

Should you expect a post every day? Not quite but it will be very frequent and at least weekly. The goal is to make 100 posts about JavaScript by the end of 2021, ready for this adventure?

## What is JavaScript, really?
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ehuru32yzkutu4jbmwc5.gif)

JavaScript is a programming language that makes web pages more dynamic. HTML is the text of a webpage, CSS is how you style it, and JavaScript is the flavor that makes things a bit more interactive. Whenever a user interacts with a page (clicking buttons, changing pages, rating a tutorial, etc), JavaScript is definitely involved. When you combine those three web technologies, you are bound to create really dope stuff.

JavaScript is a  <strong>dynamically typed</strong> language, meaning you don't have to declare a type when you're setting a value and can freely change types unlike more statically typed languages or tools like C++ where you must declare the value type when you initialize. In a dynamically typed language like JavaScript, once your code runs, the JavaScript engine will decide what type the value is so you don't explicitly have to. 

### JavaScript as a language is ever evolving
JavaScript is implemented by different browsers and it's up to those browsers to implement new features. There is an organization called <strong>ECMA</strong>, an international group in charge of different standards. <strong>ECMAscript</strong> is a specification for a programming language- rules on how it should behave and work.

<strong>TC39</strong> is a committee that is in charge of maintaining this document and every year delegates link up and determine what new features need to be added to it. This is why we have <strong>ES2015, ES2016, ES2017, 2018,</strong> etc! 

Different browsers will support different features at any time, so I highly advise you to bookmark sites like caniuse.com to stay up to date on browser compatibility for JavaScript features. Some features you'll learn like template literals will be supported by most browsers but not available on some like IE11. 

## So how do we run it??

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/psio1w5k1yam4iio2h1z.gif)
<ul>
   <li><strong>A web browser</strong></li>
   <li><strong>Any text editor</strong></li>
   <li><strong>Console</strong>- To quickly run and debug code without any setup</li>
</ul>

JavaScript only requires a web browser (like Chrome or Firefox) and a text editor. There's default text editors you can find on your laptop or desktop depending on what operating system you use like Notepad or iTerm. You can also download an editor like Sublime or Visual Studio Code (my preferred text editor because it comes with a built-in terminal). 

The JavaScript console is where you can quickly run, test and debug your code instantly. This is where you can test out what I'll be teaching you in these next few lessons.

If you're not too aware of what Dev Tools are yet, basically this is where you can inspect the elements and performance of a webpage and run code in the console. The console can be considered a playground for you now to create basic variables and functions. 

If you're in Chrome, you can also just go to View -> Developer -> JavaScript console, as shown below.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ew8eej1yffudipnglzdz.png)

If you're in Firefox, click on the Firefox Menu in the upper-right-hand corner of the browser and select Web Developer -> Browser Console. 

If you're using a different web browser, you can do a quick lookup on their search engine for how to open developer tools. But in future tutorials, I'll mainly be using Chrome Dev Tools!

Ok, enough...let's get to learning JavaScript now!

## Primitive Data Types
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0oo2vu7a4zr0ol14j5le.png)
Data types are the different types of data we use in an application. I'll be diving deeper into some of the data types in future lessons like strings, booleans, and null and undefined since I don't want to drag this blog post on too long!  

<table style="width:100%" text-align="center">
  <tr>
    <th>Data Type</th>
    <th>Definition</th>
    <th>Example</th>
  </tr>
  <tr>
    <td>String</td>
    <td>String of text encapsulated in either single- or double-quotes</td>
    <td>"We will conquer JavaScript together"</td>
  </tr>
  <tr>
    <td>Number</td>
    <td>To represent numeric data (positive, negative, whole and decimal)</td>
    <td>3, 3.5, 2.00</td>
  </tr>
  <tr>
    <td>Boolean</td>
    <td>Represents information as true or false</td>
    <td>true or false</td>
  </tr>
  <tr>
    <td>Symbol</td>
    <td>A unique identifier/value that's not equal to any other value</td>
    <td>const mySymbol = Symbol();</td>
  </tr>
<tr>
    <td>Null</td>
    <td>Intentional/explicit absence of any value, can be reassigned later</td>
    <td>const relationshipStatus = null; </td>
  </tr>
<tr>
    <td>Undefined</td>
    <td>A variable that is not assigned a value; implicit</td>
    <td>const noValue; </td>
  </tr>

</table>

## typeof function()
So a neat function that you can use to check the type of a piece of data is by typing <em>typeof</em>. Play around and experiment!
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/461fk3yqb3no9vgsty1y.png)

## Numbers
Pretty straightforward, numbers can be a type of value. You can perform mathematical operations such as division, subtraction, addition, multiplication, etc! When you're performing multiple mathematical operations at once, keep in mind that JavaScript follows PEMDAS (certain operations in a sequence are performed at a higher level of priority in others...so parantheses, exponents, multiplication, division, addition, subtraction).
<table style="width:100%">
  <tr>
    <th>Operation</th>
    <th>Symbol</th>
    <th>Meaning</th>
    <th>Example</th>
  </tr>
  <tr>
    <td>Addition</td>
    <td>+</td>
    <td>To Add</td>
    <td>2 + 2</td>
  </tr>
  <tr>
    <td>Subtraction</td>
    <td>-</td>
    <td>To subtract</td>
    <td>2-2</td>
  </tr>
 <tr>
    <td>Division</td>
    <td>/</td>
    <td>To Divide</td>
    <td>32 / 2 </td>
  </tr> 
<tr>
    <td>Multiplication</td>
    <td>*</td>
    <td>To Multiply</td>
    <td>2*2</td>
  </tr> 
<tr>
    <td>Remainder or Modulo Operator</td>
    <td>%</td>
    <td>Returns the remainder that is left after you divide the second number into the first numbers as many times as you can like 3 % 3 leaves 0  </td>
    <td>5 % 5 = 0 (5 goes into 5 five times right? So that means there is no remainder and you're left with nothing, which is the answer.)</td>
  </tr> <tr>
    <td>Exponential</td>
    <td>**</td>
    <td>To raise a number to a certain power</td>
    <td>2**2</td>
  </tr>
</table>

## A Simple Note About NaN...
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xbtrt6szuay8azht98sh.png)
When you try to perform mathematical operations (besides additions) with strings, they will return NaN (Not a Number).


## Var, Let, & Const
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0g2wd6wjkjordxfkl79i.png)
To put it rather simply, variables are how we store a value that we can later reference, use and change in the future. When we get into functions, how we are able to access and reference certain variables will change but for now let's not worry too much!

The preferred way to set variables where we can easily change the meaning/value is <em>let</em>. We used to declare variables using <em>var</em> but it is no longer considered best practice. There are some reasons why var is no longer considered best practice and we'll delve deeper into why when we address scope later on. What to keep in mind for now is that var is not strict and can potentially cause errors since you can re-declare the same variable more than once which may lead to confusion as your application grows.

There are a few other best practices to be mindful when we are declaring variables:
<ul>
 <li>Try to be as descriptive yet concise as you can when you are naming the variable</li>
 <li>We write our variables in camelCase. Examples: let myName, const currentUser  </li>
 <li>There are reserved keywords we are not allowed to use when we name variables. Examples of reserved keywords: <strong>let</strong> (as that would be super confusing), </li>
<li>You cannot have variables with the same name even if we declare with both let and const. Ex: let myName & const myName will not work!
</ul>

You can easily re-assign a value to <em>let</em> variables or re-name as they are mutable by default, but const variables cannot be reassigned. You will be met with an error. This will definitely not be the only time we address the differences between var, let and const. The topic will come up again when we address local and global scope in the context of functions so don't fret!

## Comments, Comments, Comments
Comments are how we leave reminders for our future ourselves or teammates about the code we've written. They can either be single-line or multi-line comments as demonstrated below: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/61sm7h03h7myyvewzfyo.png)

## So what's next...
We'll be covering topics such as:
<ul>
<li>Null & Undefined</li>
<li>The newest data type: symbol</li>
<li>All About Strings</li>
<li>Functions, Local & Global Scope>
<li>Loops, Arrays and Objects</li>
</ul>

And that is just a few of the countless topics we'll be covering in JavaScript. I hope this gave you a taste of what's yet to come. I hope you enjoyed so far! Feel free to leave topics or questions you would like me to address in future posts pertaining to JavaScript too!