Leveraging Web Data Class 5 Homework

Answer the following questions about JavaScript. These questions may require you to do your own research to determine the best answer.


Developer Resources


Basic

Append your name to the text between the title tags.


Describe the purpose of JavaScript, how might it relate to web mapping and visualization?

JavaScipt is a programming language that allows interactivity to be built into a website. For any online map that is interactive or dynamic, JavaScript would likely be used.


Variables

What is a variable? Provide two examples of using a variable.

A variable stores a data value. For example, c = 2, and c is the variable, or g=12, and g is the variable.


Write out how to assign the variable x equal to 10.

var x = 10;


Operators

Describe the differences between =, ==, and ===.

= sets a variable equal to a certain data value. == checks if two pieces of data are equal to one another and returns a true/false statement. === checks if two pieces of data are equal to one another and checks if they are also the same type of data. For example, '3' ==== 3 would return as false because '3' is a different type of data than 3 (text as opposed to numeric).


What would be the result of "Hello " + 10? Why?

The result would be "Hello 10" because the + signs conectates the values, since i is not a set value, but a variable, the computer does not run it as a value and allows the loop to happen.


Loops

What is the purpose of a for loop? Describe in detail the advantages of using the for loop.

A for loop executes a block of code a specified number of times. This allows a programmer to repeat a piece of code multiple times without writing out the code multiple times.


Describe the while loop in JavaScript.

A while loop executes a block of code as long as a certain condition is fulfilled.


If/Else Statements

What are the three conditional statements? Describe how each are used.

The three conditional statements are if, else, and else if. An if statment runs a specified block of code as long a a particular condition is true. An else statement runs a specified block of code as long as a particular condition is not true. An else if statement runs a block of code when a specified condition is false and another specified condition is true.


What is the difference between using two if statements together compared to using an if statement then an else if statement or else statement?

Using two if statements forces the computer to run through each statement and check whether or not it is true before returning a result- writing if x=<2 then y, if x>2 then z, means that the computer would still have to check x = 1 with each statement, even though 1 is obviously less than two. Writing if x> 2 then y, else then z allows the computer to return the value without having to check each condition.