Skip to content

Instantly share code, notes, and snippets.

@zgulde
Last active November 4, 2016 13:40
Show Gist options
  • Select an option

  • Save zgulde/c0f4d57a60813cf5af27 to your computer and use it in GitHub Desktop.

Select an option

Save zgulde/c0f4d57a60813cf5af27 to your computer and use it in GitHub Desktop.

JavaScript Review

What is the difference between == and ===? Why is it necessary to have both of these?


Rewrite the following code using the ternary operator:

var isColdOutside = true;

var clothingToWear;

if (isColdOutside) {
    clothingToWear = 'sweater and a jacket';
} else {
    clothingToWear = 'shorts and a t-shirt';
}

Rewrite the following using a for loop:

var i = 0;
while (i <= 10) {
    console.log(i);
    i++;
}

To skip to the next iteration of a loop you would use which statement?

  • break;
  • continue;

Rewrite the following using a switch statement:

// assume getWeatherConditions will return one of 'rain', 'snow', 'clear'
var conditions = getWeatherConditions();

if (conditions == 'rain') {
    console.log('bring an umbrella!');
} else if (conditions == 'snow') {
    console.log('What!? In San Antonio?');
} else if (conditions == 'clear') {
    console.log('It\'s a nice day!');
}

What is the difference between inline and external JavaScript? Why would you use one over the other?


What does the following code output?

console.log(10 % 3);
  • 3
  • 3.3333333
  • 0
  • 1

Do the following evaluate to true or false?

  • "" == false
  • 0 === false
  • "42" != 42
  • `"42" !== 42``

The following expressions are shorthand, write out the longhand version.

  • i++
  • x -= 5
  • x /= 3
  • myString += ', and thanks for all the fish';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment