Java Script Quiz 483F
i < 5;
Consider the simple for loop below. Which part of the loop tests to determine whether the loop should run? for (var i = 1; i < 5; i += 1){}
aCounter += 3;
Consider the variable aCounter shown below. How can you increment aCounter by three?
myArray[0]
How can you access the first element in an array called myArray that has four elements?
Set the line myNum = 5;} to var myNum = 5;}.
How can you change the following code such that the value of the variable myNum is not changed from 32 to 5?
typeof aThing;
How can you determine something declared as aThing is an array or not?
A
How can you write a function that takes in two numbers and outputs their sum, but will also output the sum of 5 and 7 if no inputs are given?
myFunction();
How do you call a function named "myFunction"?
alert("Hello World");
How do you write "Hello World" in an alert box?
The === operator compares values and data types, while the == operator compares only values.
How is the strict equality operator === in JavaScript different than the equality operator ==?
It can have as many as you need for your function.
How many arguments can a JavaScript function have?
var aString = '12';
How should you declare a variable called aString containing the string 12?
B
How should you declare and then call a function named myFunction() that takes no inputs and prints out myFunction was called?
Start with local scope. Global variables are globally modifiable, which can cause issues.
How should you define the scope of your variables when first starting to program, and why?
if (i != 5)
How to write an IF statement for executing some code if "i" is NOT equal to 5?
node.js
If you are planning to use JavaScript for backend development, which option is your best choice? Correct answer:
true and false
In JavaScript, what are the two possible states of a Boolean?
if (logState) console.log("The state is true");
In the below code block, how can you code the if statement to be more compact but equivalent to the original if statement?
The command myArray.length; will report a length of 6.
In the following declared array, how should you determine the length of the array and what is that length?
5
In the following function declaration and call, what should you expect the output to be?
True
Is JavaScript case-sensitive?
False
JavaScript is the same as Java.
var c1="Red", c2="Green", c3="Blue";
On a single line, how can you assign the colors red, green, and blue to three variables called c1, c2, and c3, respectively?
else { console.log("The number is not 0");}
The following code block tests whether aNum is equal to the value 0. How can you add to the code to report when the number held in aNum is not 0?
Functions can be passed around as values
What does it mean that functions are objects in JavaScript?
let colors = ["red", "green", "blue"]
What is the correct way to write a JavaScript array?
/* Comment Line 1 Comment Line 2 */
What is the proper format for creating a comment block?
The output will be 32. The myVar variable within the function is a different variable than the myVar variable outside of it.
What output should you expect if you add console.log(myNum); to the code below, and why?
if (i = 1)
Which of the following JavaScript IF statement is incorrect?
You can reuse variables to contain different data types.
Why is JavaScript considered a loose typing language?
A while loop is better than a for loop if you do not know how many times you have to loop.
Why would you consider using a while loop instead of a for loop?
It creates a reference from animal2 to the original object animal1.
You create an object called animal1. Next, you enter animal2 = animal1;. What does this line do?
as a property
You have a string called myString. How is the command myString.length classified?
myArray.pop();
You have an array called myArray of length 5. How should you remove the very last element in the array?
Math.ceil(aVar);
You have declared the variable aVar to have a value of 55/3. How should you use JavaScript's Math function to return a value of 19?
color === "black" && size === 5;
You have two variables, color and size. You want to test whether color is equal to the string black and whether size is equal to the number 5. How can you do this?