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:

  1. Repeat a piece of code a different number of times using a variable.
  2. See what variable names work and which do not.
  3. 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 phrase
let 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 Names
let 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 data
let x = 235987;
let isValidEmail = true;
let favGuitar = 'Stratocaster';
console.log(x);
console.log(isValidEmail);
console.log(favGuitar);

Explore Data Types

Explore data types!

Explore:

  1. What data types are 348, false, "a phrase", respectively?
  2. What is the data type of a "27" or "false"? Try with and without quotes.
  3. Is there a difference between the data type for a phrase with double quotes or single quotes?
  4. What happens when you add two numbers with and without quotes around them?
// Using typeof keyword to determine the data type
let 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 typeof
console.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);