CGS 3066 Midterm 2 Flashcards

(18 cards)

1
Q

A hoisted function is:

A

A function whose declaration appears after the line that calls the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A hoisted function is:

A

A function whose declaration appears after the line that calls the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Select the correct way to load a JavaScript file in a HTML file

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the purpose of the defer keyword?

A

To postpone the execution of a JS script until the page is fully loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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);
A

The code throws an error.

const is not reassignable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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:

A

document.querySelector(‘#button1’).addEventListener(‘click’, eventHandler);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Select the correct way to load a JavaScript file in a HTML file

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the defer keyword?

A

To postpone the execution of a JS script until the page is fully loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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:

A

const input = form.first-box.value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
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);
A

The code throws an error.

const is not reassignable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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):

A

link.href = “http://www.newdestination.com”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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:

A

div1.removeChild(div2);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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:

A

const input = form.first-box.value;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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:

A

myDiv.classList.add(‘error’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

False, they must have the same “name” attribute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True/False: In JavaScript, a variable created with the var keyword has function-level scope.

17
Q

True/False: The DOM object is a linked-list based representation of the elements in a web page.

A

False, tree-based

18
Q

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.

A

False, counter example: radio input types share the same “name” attribute. But this is true for most other types