Explore Variables & Data Types
Welcome to your first explore section!
This gives you a chance to work with code and experiment. Copy and change the code to understand it.
Explore Variables
Explore variables!
Explore:
- Repeat a piece of code a different number of times using a variable.
- See what variable names work and which do not.
- Reassign the variable.
// We use variables so we don't have to repeat the data over and over.console.log("Imagine there is a phrase you want to reuse a several times");console.log("Imagine there is a phrase you want to reuse a several times");console.log("Imagine there is a phrase you want to reuse a several times");console.log("Imagine there is a phrase you want to reuse a several times");console.log("Imagine there is a phrase you want to reuse a several times");// You can use a variable to reuse the phraselet imaginePhrase = "Imagine there is a phrase you want to reuse a several times";console.log(imaginePhrase);console.log(imaginePhrase);console.log(imaginePhrase);console.log(imaginePhrase);console.log(imaginePhrase);// Variable Nameslet whatWorksAsAVariableName = "Here is a sentence!!!";console.log(whatWorksAsAVariableName);console.log(whatWorksAsAVariableName);// Changing the Variable// Start with the variable assigned to one thing.let favoritePie = "Strawberry Rhubarb Pie";console.log(favoritePie);// And then you can change it.favoritePie = "Apple Pie";console.log(favoritePie);// A variable can hold different types of datalet x = 235987;let isValidEmail = true;let favGuitar = 'Stratocaster';console.log(x);console.log(isValidEmail);console.log(favGuitar);
Explore Data Types
Explore data types!
Explore:
- What data types are 348, false, "a phrase", respectively?
- What is the data type of a "27" or "false"? Try with and without quotes.
- Is there a difference between the data type for a phrase with double quotes or single quotes?
- What happens when you add two numbers with and without quotes around them?
// Using typeof keyword to determine the data typelet favoritePie = "Strawberry Rhubarb Pie";console.log(typeof favoritePie);console.log(typeof 'hello');console.log(typeof "hello");console.log(typeof 'false');console.log(typeof 'true');console.log(typeof true);console.log(typeof 8);console.log(typeof 1348);// A second syntax for typeofconsole.log(typeof(true));console.log(typeof("A phrase in quotes"));// A Difference Between Strings and Numbers// Guess what will print before running this program.let resultOne = 2 + 3;let resultTwo = '2' + '3';console.log("The type of result one is: " + typeof(resultOne) + "\n The value for result one is: " + resultOne);console.log("The type of result two is: " + typeof(resultTwo) + "\n The value for result two is: " + resultTwo);