JavaScript Study Guide

Jon Ippolito

Version 2.7

Questions from the JavaScript quizzes as well as the following topics will be on the test:

Which syntax JavaScript treats strictly and which it treats loosely

Line breaks

Lower versus upper case

Variable types (strings versus integers versus booleans)

White space on the same line (tabs versus spaces)

What character separates multiple JavaScript commands on the same line?

(Think about the beginning of a for loop)

The exact syntax for adding an external JavaScript to a Web page. (Don't forget the closing tag!)

< _________   _____ = "myScript.js" >< / _________ >

Two ways to make comments in JavaScript.

// versus /*...*/

How to define a variable that can change, a local variable, and a variable passed in a function (the "argument").

Which is let?

Which is const?

How to identify a string, and two ways to concatenate (stick together) strings and variables in an expression.

"Welcome to our site, " + userName

`Welcome to our site, ${userName}`

Symbols for conditional statements such as less than, equal to, etc.

=

versus

===

The exact syntax for writing an if statement.

if ( ____ === _____ ) {

        ___________

}

else {

        ___________

}

The exact syntax for writing a for loop with a predefined number.

for ( var counter = 0 ; counter < 20 ; counter ++ ) {

        ___________

}

The exact syntax for writing a for loop that runs through an array.

for ( var counter = 0 ; counter < cats.length ; counter ++ ) {

        ___________

}

The exact syntax for writing a forEach loop that runs through an array.

cats.forEach(

       cat => cat.___________

}

How to notify or get info from the user quickly

        alert( "Hey bud!" ) ;

        let horoscope = prompt( "What's your astrological sign?" ) ;

The exact syntax for writing a JavaScript function.

sayHi = function( message ) {

        alert( message ) ;

}

or

sayHi = (message) => {

        alert( message ) ;

}

Arrays: how to create one, get its length, identify its 1st, 2nd, 3rd element, etc.

cats = [ ] ;

cats.length

cats[0], cats[1], etc.

cats.push( "Grumpy" )

How to identify and manipulate HTML tags (the "DOM").

document.querySelector( "#Lucy" )

document.querySelectorAll( ".kitten" ).forEach( div => ... )

document.querySelectorAll( "div" ).forEach( div => ... )

myKittenDiv.innerHTML = "Grumpy" ;

How to set an HTML element's style in JavaScript. What happens to:

The selector (# for an id, . for a class, or a tag name)

The braces {} around the style rule.

The hyphen in a style attribute like background-color.

A value like blue.

The colon : separating the property and value.

Example:

#catDiv {

background-color: blue ;

}

document.________________( "__________" ).______.background__olor __ _______ ;

What does this mean when used in a function called from a click or rollover?