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?