Well done!
You have completed Hello Full Stack JavaScript !
You have completed Hello Full Stack JavaScript !
One of the fundamental concepts of JavaScript and other programming languages is the ability to store values in variables. JavaScript allows us to attach values to names so they can be easily reused and understood in programs. Variables have different types to represent different types of data which all come with their own methods and properties.
Further Reading
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upBefore we go any further with JavaScript, 0:01 it's helpful to know that it utilizes different data types. 0:03 As you've seen, JavaScript can work with characters surrounded by quotes and 0:07 does this using its string data type. 0:11 Strings represent sequences of symbols and must be wrapped in quotation marks. 0:15 Besides strings, JavaScript also has other data types. 0:20 The first we'll discuss are numbers. 0:24 These represent real numbers. 0:27 We can use them to keep track of scores and counts and 0:29 perform mathematical operations on them. 0:32 There's also a type called Booleans. 0:36 Booleans represent true and false values and 0:38 come in handy when a program has to make decisions. 0:41 JavaScript has other built in data types and ways to store and keep track of data. 0:45 You'll learn all about those in Treehouse's JavaScript courses. 0:51 Now that we know about different data types, 0:56 let's learn how to use them efficiently in programs. 0:58 Storing data to access or update later is a common task in JavaScript. 1:02 JavaScript allows us to name and reuse values by storing them in variables. 1:08 Think of a variable as a jar with the label indicating what's inside. 1:14 At any time, we can look inside the jar, 1:18 we can even change what's inside the jar or empty it. 1:21 Even though what gets stored in the jar might change, 1:25 it's always the same jar with the label we gave it. 1:28 Just like we can store something inside a jar, 1:32 we can store data inside a JavaScript variable with a unique name. 1:34 Whenever we want to access what's inside that variable, we reference its name. 1:39 Okay, so from that example, 1:46 we know a variable has two parts, a name and a value. 1:48 In JavaScript, the syntax for creating a variable 1:53 requires beginning with the keyword var, let or const. 1:57 Using one of these keywords lets the program know we're preparing to define 2:02 a variable. 2:06 We'll start by using var in this workshop. 2:08 The var keyword is followed by the name we choose for the variable. 2:11 We then use the assignment operator or equal sign, 2:16 which in JavaScript can be used to assign a value. 2:19 Finally, we assign the variable a value, 2:23 which can be any of the types I've mentioned or more. 2:25 For example, we can name a variable with just a single letter and 2:31 set it equal to a value of our choice. 2:35 Normally though, we'll want to use a more 2:39 descriptive variable name to make our programs more readable. 2:41 Let's create a variable to store our favorite foods. 2:45 I'll pick mine, but for practice, I want you to choose your own. 2:50 First in the console, we'll write the var keyword, 2:55 followed by the variable name favoriteFood. 2:58 Next we'll use the assignment operator or 3:06 equal sign to set the variable equal to sushi. 3:09 Now if we press Enter, 3:17 then type the variable name favoriteFood again, and press Enter. 3:18 The value stored in favoriteFood is printed to the console. 3:24 Nice work. 3:27 You've learned one of the building blocks of JavaScript. 3:29 The most powerful programs rely on variables for storing, 3:31 accessing and modifying data. 3:36 Next, we'll go further and use JavaScript to operate on values stored in variables. 3:39
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up