A variable is an identifier for a value. The most common way that variables are used is with the “let” keyword, followed by the name of the variable. An example of this would be: let myText . When the variable has a name, but does not have a value, it is what’s known as declared. It should be given a value, though, so that it serves a purpose. This process is known as initializing the variable. To initialize the variable, you use an equals sign (known as the “assignment” operator) to assign the variable to the contents of the value. For example: let myText = “Good morning!”; . In addition, you should use quotation marks around the contents of the value. Declaring and initializing variables are very important steps in coding, but they also have their differences. Declaring a variable is giving it a name, and initializing it is giving it a value.
Reader Interactions
Comments
Leave a Reply
You must be logged in to post a comment.
Hi Madeline,
Your explanation and steps of what a variable is helped me a lot. I had trouble finding a variable at first, but your example of “let myText” being declared and then showing how to initialize the variable “myText= Good Morning!” was perfect.