DEV Community

Jennifer Tieu
Jennifer Tieu

Posted on • Updated on

Self-Taught Developer Journal, Day 21: TOP JavaScript Fundamentals Part 1 - Variables

Today I learned....

JavaScript Variables

To create a variable in JavaScript us the let keyword.

let message = Hello;
Enter fullscreen mode Exit fullscreen mode

var is an old school way of declaring a variable. This declaration exists in older scripts. Declaring a variable twice will trigger an error.

There are two variable naming limitations:

  1. The name must contain only letters, digits, or the symbols $ and _.
  2. The first character must not be a digit.

camelCase is commonly used naming convention, for example, newToy.


Constants is an unchanging variable meaning the value cannot be reassigned. The keyword to use is const. When declaring a variables, its a general rule to use const unless you know the value will change. I'm guessing this is to prevent any accidental reassignment of a value.

Uppercase Constants

It is a common practice to use constants as aliases for difficult-to-remember values that are known prior to execution.
They are named using capital letters and underscores.

Capitol Constant vs Not

A capitol constant name is used when the value is known prior and is hard-coded in.
A lower case constant is calculated run time and doesn't change after initial assignment.

Constant Objects and Arrays

const does define a constant value, but a read-only reference to a value. For this reason, the value cannot be reassigned or redeclared, but you can change the elements of constant array and change the properties of constant object


The Odin Project

Day 20:
Please refer to Starting My Self-Taught Developer Journey for context.

Discussion (4)

naruaika profile image
Naufan Rusyda Faikar • Edited on

By the way, we can create a series in instead of adding hyperlinks referring to your previous posts.


jennifer_tieu profile image
Jennifer Tieu Author

That is good to know, I'll look into it. Thank you!

toddpress profile image
Todd Pressley

I’m “self taught” too, so i can appreciate the difficulty of and dedication that it takes to learn and synthesize content daily. Great article! Keep ‘em coming!

One thing that may be worth exploring or elaborating upon is that const identifiers’ values are still mutable when the type is complex (e.g. array and object)... constant doesn’t mean immutable in these cases.

jennifer_tieu profile image
Jennifer Tieu Author

Thank you! I appreciate you taking the time to read it and leaving feedback. For the constants, I was thinking in terms of basic data type. I'll explore it some more though and update it.