Introduction to JavaScript – Variables

Introduction to JavaScript – Variables

Programmers use variables to write code that is easy to understand and repurpose.

Imagine you’re writing a weather app. Your thermometer outside reports the temperature in Celsius, but your goal is to record the temperature in Fahrenheit.

You write a program that takes a temperature of 15 degrees Celsius and calculates the temperature in Fahrenheit.

Once you’ve done this though, you see the temperature now reads 16 degrees Celsius. To find Fahrenheit again, you’d need to write a whole new program to convert 16 degrees Celsius to Fahrenheit.

That’s where variables come in. Variables allow us to assign data to a word and use the word to reference the data. If the data changes (like degrees Celsius) we can replace the variable’s value instead of re-writing the program.

In this lesson you will learn about two ways to declare variables: let and const.

// This line of code sets the variable location1 to the string New York City
const location1 = 'New York City';

// This line of code sets the variable latitude to the number 40.7
let latitude = 40.7;

// This line of code sets the variable inNorthernHemisphere to true
let inNorthernHemisphere = true;


New York City

Introduction to JavaScript – Variables

Related Videos: Related Videos.

Related Links:

Designing an app in Pseudo code

See the JavaScript Glossary on Variables Variables

Online JavaScript Compiler. Code on the go.

Introduction to Python Programming Language

My little pony learning game in VB.NET

Adding Python Comments

Introduction to JavaScript – Data Types

Introduction to JavaScript – Properties

Introduction to JavaScript – Variables: String Interpolation

Introduction to JavaScript – Variables: Review

Exception Handling in Python programming

What is Python?

Who is this Android App Development course for?

How to make a go-back button with PHP code?

Introduction to JavaScript – Create a Variable: let

Learn Partial functions Python programming

Defining What an Application Is

Android Studios

Hello World Android app built with Android Studio

Introduction to JavaScript – Control Flow: if/else Statements

Introduction to JavaScript – Create a Variable: const

Introduction to JavaScript – Review Types and Operators

Google’s “Grasshopper” Mobile Game Teaches Adults How To Code In An Easy, Accessible Way — And It’s Free

Why do most sites use cookies?


Connected through code, Choose Your Platform!

About the Author: Bernard Aybout

In the land of bytes and bits, a father of three sits, With a heart for tech and coding kits, in IT he never quits. At Magna's door, he took his stance, in Canada's wide expanse, At Karmax Heavy Stamping - Cosma's dance, he gave his career a chance. With a passion deep for teaching code, to the young minds he showed, The path where digital seeds are sowed, in critical thinking mode. But alas, not all was bright and fair, at Magna's lair, oh despair, Harassment, intimidation, a chilling air, made the workplace hard to bear. Management's maze and morale's dip, made our hero's spirit flip, In a demoralizing grip, his well-being began to slip. So he bid adieu to Magna's scene, from the division not so serene, Yet in tech, his interest keen, continues to inspire and convene.