CGS 3066 Midterm 2 Flashcards
(18 cards)
A hoisted function is:
A function whose declaration appears after the line that calls the function
A hoisted function is:
A function whose declaration appears after the line that calls the function
Select the correct way to load a JavaScript file in a HTML file
What is the purpose of the defer keyword?
To postpone the execution of a JS script until the page is fully loaded
Given the following snippet of JS code, what is the expected output?
const output = ' '; for ( let i = 1; i <= 5; i++ ) { output += i + ','; } console.log(output);
The code throws an error.
const is not reassignable
Assume that you have the following element in your HTML page
< input type=”button” name=”the_button” id=”button1” value=”Click me” class=”button-style” />
Select the correct statement to add an event listener to that element:
document.querySelector(‘#button1’).addEventListener(‘click’, eventHandler);
Select the correct way to load a JavaScript file in a HTML file
What is the purpose of the defer keyword?
To postpone the execution of a JS script until the page is fully loaded
Assume you have the following HTML form in your web page:
And the following JS event handler for the form submission:
function submission (event) { const form = event.target; const input = //TO DO }
input will store the data the user entered in the “text” element. The correct JS code to capture such entered data inside the input variable is:
const input = form.first-box.value;
Given the following snippet of JS code, what is the expected output? const output = ' '; for ( let i = 1; i <= 5; i++ ) { output += i + ','; } console.log(output);
The code throws an error.
const is not reassignable
Assume that you have the following line of JS code
const link = document.querySelector (“a”);
Which obtains a reference to a link element in the web page. Select the correct JS statement to change the destination of that link (i.e., the webpage that is loaded when the user clicks the link):
link.href = “http://www.newdestination.com”
Assume that you have the following element in your web page:
< div id="div1" > <div> </div> <div> </div>
And the following two JS statements:
const div1 = document.querySelector('#div1'); const div2 = document.querySelector('#div2');
Select the correct JS statement to remove div2 from the DOM:
div1.removeChild(div2);
Assume you have the following HTML form in your web page:
And the following JS event handler for the form submission:
function submission (event) { const form = event.target; const input = //TO DO }
input will store the data the user entered in the “text” element. The correct JS code to capture such entered data inside the input variable is:
const input = form.first-box.value;
Assume you have the following JS code, which captures a reference to a div element in the web page
const myDiv = document.querySelector(‘#the_div’);
Then you plan to add an existing CSS rule called ‘error’ to that element, so the div somehow alerts the user that something went wrong. Select the JS statement that properly adds the CSS rule to the element:
myDiv.classList.add(‘error’);
True/False: In an HTML form, when you use several radio input types, all must share the same ID to prevent the user from choosing more than one option.
False, they must have the same “name” attribute
True/False: In JavaScript, a variable created with the var keyword has function-level scope.
True
True/False: The DOM object is a linked-list based representation of the elements in a web page.
False, tree-based
True/False: In an HTML form, every element inside a form must have a unique value for its “name” attribute, since such a value will be sued to handle the data contained in the form.
False, counter example: radio input types share the same “name” attribute. But this is true for most other types