Leveraging Web Data Class 5 Homework
Anna Malek

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?

JavaScript is a powerful and popular language for programming on the web. D3.js is a JavaScript library that offers powerful data visualization features for producing dynamic, interactive data visualizations in web browsers.


Variables

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

JavaScript variables are containers for storing data values.
A string variable is a series of characters like "John Doe".
variable as a number, for example: var x = 34;


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

var x = 10


Operators

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

A single equal operator is used to assign a value to a variable
When a comparison is made using a double-equals operator, it will check the values of a variable and convert them to a common type and returns true if both are equals. So comparing number with a string having the same value will return true.
for example: console.log(23 == "23"); // true
In contrast to double equals operator, another operator with three equals not made the implicit conversion so it not only compare values but also the type of variable that's why it is also called strict comparison.
for example: console.log(23 === "23"); // returns false


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

The result for 10 is "Hello" because 10 is divided by 5 and the remainder of operation is equal to zero.


Loops

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

For loop is used to run the same code over and over again, each time with a different value.


Describe the while loop in JavaScript.

The while loop loops through a block of code as long as a specified condition is true.


If/Else Statements

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

The if statement specifies a block of code to be executed if a condition is true
The else if statement specifies a new condition if the first condition is false
The else statement specifies a block of code to be executed if the condition is false


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

In our example the loop number (15) has to be divided by 3 & 5 to meet the first condition(execute "Hello World"). If we use if (i % 3 == 0), else if (i % 5 == 0), the first condition would be executed for 15 ("World") and the program would not check the second condition.