Every valid web page can be represented as a tree. This tree is referred to as the
1) JavaScript
2) DOM
3) API
ANS: 2) DOM
JavaScript uses what kind of interface to access the DOM structure?
1) CSS3
2) an API
3) HTML5
ANS: 2) an API
Which of these is not valid? (Hint, pay attention to if the method should return one thing, or many things...)
1) document.getElementsById(idName)
2) document.getElementsByClassName(className)
3) document.getElementsByTagName(tagName)
ANS: 1) document.getElementsById(idName)
Which of the following is not a valid method for generating output to the screen?
1) prompt
2) alert
3) document.write
4) print
ANS: 4) print
Which of these options does NOT require the use of parentheses?
1) innerHTML
2) alert
3) document.write
4) console.log
ANS: 1) innerHTML
Which of the following does not generate output directly to the screen?
1) document.write(message);
2) element.innerHTML = message;
3) console.log(message);
ANS: 3) console.log(message);
How does prompt differ from alert?
1) Only prompt uses parentheses.
2) The prompt will return a value, alert does not.
3) The alert will return a value, prompt does not.
4) Only alert uses parentheses.
ANS: 2) The prompt will return a value, alert does not.
Variables allow you to save data.
1) True
2) False
ANS: 1) True
In JavaScript the keyword ___________ is used to declare a variable.
ANS: var
What does it mean that variables are case-sensitive?
1) That all variables must use uppercase letters
2) That the computer does not think that the variables name and Name are the same thing.
3) That all variables must use lowercase letters
ANS: 2) That the computer does not think that the variables name and Name are the same thing.
Which of the following is not a valid variable name?
1) variable1
2) variableOne
3) 1variable
4) oneVariable
ANS: 3) 1variable
Which of the following is not a valid variable name?
1) variable$2
2) variable-2
3) variable_2
ANS: 2) variable-2
What does mnemonic mean?
1) That variable names should start with lowercase letters and use uppercase letters if the variable has multiple parts, e.g. firstName.
2) That variable names should be as short as possible, preferably with no more than two or three characters.
3) That variable names should help describe the value being stored.
ANS: 3) That variable names should help describe the value being stored.
What is wrong with this code?
var name = "Mike";
"Colleen" = name;
1) It is illegal to change the value stored in a variable.
2) This code is illegal and it doesn't make sense to have a non-variable (also called a constant) in the left-hand side (LHS) of an assignment statement.
3) The variable declaration is illegal.
ANS: 2) This code is illegal and it doesn't make sense to have a non-variable (also called a constant) in the left-hand side (LHS) of an assignment statement.
What value is stored in name if the person hits the Cancel button on a prompt?
var name = prompt("What is your name?");
ANS: null
What value is stored in name if the person hits the Okay button on a prompt before entering anything?
var name = prompt("What is your name?");
1) an empty string ("")
2) undefined
3) exception
ANS: 1) an empty string ("")
To create a String variable, use quotes around the value you want to save.
1) True
2) False
ANS: 1) True
Boolean variables store either true or false.
1) True
2) False
ANS: 1) True
When a function returns a node from the DOM, it is of type
1) Number
2) String
3) Boolean
4) Object
ANS: 4) Object
A function that wants to return multiple values at once (such as document.getElementsByTagName) will return a/an
1) Number
2) String
3) Array
ANS: 3) Array
Which of the following is not a valid operator?
1) =+
2) +=
3) ==
4) ++
5) --
ANS: 1) =+
What value is returned by 17 % 5?
ANS: 2
What is the difference between == and === ?
1) The == operator only checks for equivalent values, not equivalent type too.
2) The === operator only checks for equivalent values, not equivalent type too.
3) The == operator is the assignment operator, while === is the equality operator.
ANS: 1) The == operator only checks for equivalent values, not equivalent type too.
What is the logical operator for AND?
ANS: &&
Which tag is used to let the browser know that it is about to see JavaScript code?
1) <script>
2) <head>
3) <javascript>
ANS: 1) <script>
JavaScript code must be placed in the section of the document.
1) True
2) False
ANS: 2) False