DEV Community

Cover image for Javascript Data Types - The Beginners Guide To Javascript(Part 1)
Cameron Lucas
Cameron Lucas

Posted on • Updated on

Javascript Data Types - The Beginners Guide To Javascript(Part 1)

Intro To Javascript

"Any application that can be written in Javascript, will eventually be written in Javascript" - Atwood's Law

Javascript's rise in popularity and the flexibility to create mobile, web, desktop, front-end, and back-end applications has made it one of the most popular programming languages in recent years. Paired with its loosely-typed syntax makes it an easy language for beginners to learn.

If you didn't understand anything above, don't stress, understanding the lingo is only one part of becoming a Software Engineer, and you will pick it up over time. I'm glad you are here and taking the first steps of learning a programming language. Enough small talk let's get right into it!

Variables

Variables are a critical part of every application. Variables allow us to store/hold and reuse data throughout our applications. This data is stored in a "slot" in your computer's memory(RAM). The variable is a reference to this point/slot in memory. Javascript currently has three ways of declaring a variable. var, const, and let

const name = "Cameron";
let age = 25;
var status = "Codding...🧑🏼‍💻";
Enter fullscreen mode Exit fullscreen mode

The main difference between var and const | let is scope. Scope is an important concept to understand but can be hard to grasp. Not to worry, we will cover scope in the future.

The difference between let and const is that let lets you reassign the data that variable points to in memory. With const the data can only be assigned once.

const name = "Cameron";
let age = 24;

age = 25; // OK ✅
name = "David"; // ERROR ❌
Enter fullscreen mode Exit fullscreen mode

When naming a variable in Javascript its convention to use lowerCamelCase. Variables cannot start with a number but can contain numbers.

Variables are also case-sensitive.

const carEngineRunning = true

const car3 = "Subaru WRX" // OK ✅
const 3rdCar = "Subaru WRX" // ERROR ❌
Enter fullscreen mode Exit fullscreen mode

So when do I use const, let, or var?

"const until you can't" - Cameron's Law of Const

You have seen three different types of data stored in variables, including Booleans, Strings, and Numbers. Javascript has 7 Primitive Data Types(Booleans, Null, Undefined, Numbers, BigInt, Strings, and Symbols) and Objects. Let's get into the meat and potatoes and take a look at each of these Data Types.

Primitive Types

Boolean Type

Booleans can have two values true or false

const isOnline = true;
const hasUnreadMessages = false;
Enter fullscreen mode Exit fullscreen mode

Null Type

Null has only one value null we use null to specify that a variable has no "real" value.

const goldCoins = null;
Enter fullscreen mode Exit fullscreen mode

Undefined Type

Undefined is assigned to variables that have never been assigned.

let gasPoint;

console.log(gasPoint); // undefined
Enter fullscreen mode Exit fullscreen mode

Numeric Types

Unlike other programming languages, Javascript doesn't differentiate between integers(1, 15, 24) and floating-point/decimals(3.14, 1.23, 0.99), and all of the examples are considered Numeric Types

const age = 24;
const balance = 1204.32;
Enter fullscreen mode Exit fullscreen mode

BigInt Types

A BigInt value can hold a massive integer value but it is not commonly needed or used. we will not cover it here now, but it's good to know it exists.

String Types

A string is textual data and is normally wrapped in single or double quotes.

const name = "Cameron";
Enter fullscreen mode Exit fullscreen mode

Symbol Types

Symbol types are unique and immutable(can not be changed) values that may be used as the key of an Object property. Their use is rare in general Javascript programming.

Objects

Most programming languages have different Types that hold/store more complex data structures. Javascript only has one, Objects.

Objects are collections of zero or more key:value pairs known as properties. We will cover Objects in-depth in the future. With that said, here is how we may represent a user/person as an Object.

const user = {
    firstName: "David",
    lastName: "Green",
    age: 27,
    favColor: null,
    savingsBalance: 23576.92
}
Enter fullscreen mode Exit fullscreen mode

Wow, that was a lot of information, and we have learned a lot.

  • We learned a little about Computer Science and how applications store data in our computer's memory.
  • We talked about why variables are so important.
  • We touched on each of the different Data Types in the Javascript langue.

Don't be afraid to re-read this blog post if needed. This is the beginning of a blog post series and, we will be covering the Javascript language in-depth.

Top comments (0)