DEV Community

Jennifer Tieu
Jennifer Tieu

Posted on • Edited on

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

Today I learned....

JavaScript Variables

To create a variable in JavaScript use 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

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

Resources

The Odin Project
https://www.w3schools.com/js/js_const.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

Day 20: https://dev.to/jennifer_tieu/self-taught-developer-journal-day-20-top-landing-page-cont-the-fourth-section-and-footer-57b
Please refer to Starting My Self-Taught Developer Journey for context.

Top comments (4)

Collapse
 
naruaika profile image
Naufan Rusyda Faikar • Edited

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

Screenshot

Collapse
 
jennifertieu profile image
Jennifer Tieu

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

Collapse
 
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.

Collapse
 
jennifertieu profile image
Jennifer Tieu

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.