JavaScript: Variables
Overview
Variables are used to store values. These values can be primitive like a number, string, Boolean, or null or they can be objects like a function, class, or literal object. The values can be used as input to expressions, used in processing, or used in output to display information.
To give you a better understanding of how JavaScript works, core features and control
structures of the language are provided throughout the course, including variables. It's worth
noting
that these programming structures and concepts are common to all programming
languages. The use cases should be a review of what you have already learned in the pre-requisite
courses.
Prepare
- Answer the following questions using this resource Storing information that you need - Variables - MDN Web Docs or
through your own research.
- What is the difference between
const
andlet
? - Define the string data type.
- Which should you use to wrap strings, single quotes('), double quotes("), or backticks(`)?
- What is a template literal and why is it used to build strings?
- What is the difference between
- What are code comments and how are they written in JavaScript?
- Code commenting is a way to document your code for yourself and others who may read your code.
- Example of how to incorporate code comments: CodePen Example
Check Your Understanding
- Open up this CodePen JavaScript
Variables.
You might consider creating your own free CodePen account to use to store snippets of code. CodePen provides a web-based code editor where you can write HTML, CSS, and JavaScript code and see the live results in real-time.
- Read the instructions in the JavaScript tab in the CodePen window.
- Ponder the given questions as you work through the code examples and review the output.
► Demonstration Video: JavaScript Variables Activity
Optional Resources
- JavaScript Basics - Variables - MDN Web Docs.
- Variables - Understanding Variables in JavaScript? - WDD Learning Modules
- Test your skills: variables - MDN Web Docs