How to create a variable in JavaScript

You can think of variables as a way to store information that might be needed on an application. To define a variable, you can use var, let, or const!

var myFavoriteNumber = 7
let myFavoriteFood = "Cereal"
const myFriendsName = "John"

The variable myFavoriteNumber contains the number 7.

The variable myFavoriteFood contains the word "Cereal"

The variable myFriendsName contains the word "John"

An Example

Lets say you're trying to remember what your friends name is. An easy way to keep this information in your application would be creating a variable and storing your friends name inside of it!

So our exact steps would be:

  1. Create a variable
  2. Assign it the value of your friends name
#Create The Variable and Assign it your Friends Name
var myFriendsName = "Spongebob"