Applied JavaScript Flashcards

1
Q

The getAttribute() method retrieves the corresponding value of an attribute. What if attribute doesn’t exist?

A

If the attribute does not exist, an empty string is returned.

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

Which event handler of the select object specifies the JavaScript code to execute when a user moves the cursor to the select list?

A

The onfocus event handler of the select object specifies the JavaScript code to execute when a user moves the cursor to the select list.

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

The hidden element remains unseen to a user on a webpage and while submitting the form. Since it cannot be seen, its value remains unchanged by the user. Although the user can still change the value of a hidden field through the use of browser developer tools.

A

True

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

The Safari browser doesn’t support the email and URL objects. The Internet Explorer browser does not support the color object.

A

True

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

Which property of the form object returns the number of elements in the form?

A

length
The length property of the form object returns the number of elements in the form because each form element has a name and a value property.

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

Which form event handler executes the specified code when the value of an element is modified from the default?

A

The onchange event handler is used to specify the code to execute when the value of the form element is modified from its default value.

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

Which event is triggered on the element when the selection is modified?

A

The onchange event is triggered when a user changes the selection from the default to any other value from the selection list. The event is triggered when the object loses its focus after a selection is made.

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

Which property is used to control the granularity of the range input type?

A

The step property of the range input type controls the granularity or the interval between each acceptable values.

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

Which example shows proper JavaScript syntax for referring to a form object named newForm having a text box named fieldName?

A

The document interface is the first element that will help to refer the form element through both the form name and the element name, the form object is subordinate to the document object in the JavaScript object hierarchy. So, the correct syntax is:

document.newForm.fieldName.value;

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

Which of the following expressions will make sure that a user enters a value in the text field before submitting the form?

A

The document.forms[0].elements[0].required = true; expression adds the required property to the element in the form, which makes sure that a value is entered in the input field before the form can be submitted.

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

Which event handler of the select object specifies the JavaScript code to execute when the select object loses focus after a user makes a selection, but only if the user selects an option other than the default?

A

The onchange event handler specifies the JavaScript code to execute when the object loses focus after a user makes a selection, although the change event occurs only if the user changes the selection from the default.

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

Which of the following protocols is used to protect the user data during transmission?

A

Secure Sockets Layer (SSL) based transmission makes sure that the data sent between the client and the server is encrypted during transmission, and is not easily eavesdropped by a third party. SSL also prevents the data from being transmitted between the end user and the server from being tampered with or changed.

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

Which attribute of the file object is used to define the types of files to be uploaded?

A

The accept property of the file object (input type=”file”) is used to set or return the types of files that will be accepted for upload.

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

Which method can be used to increase option elements in the select object?

A

The add() method can be used to append elements to the select object in the options collection.

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

A user enters confidential data on a website while performing a task. This data was redisplayed on the webpage after the task was completed. The data sent between a server and a browser was not encoded as HTML entities. Which of the following vulnerabilities will occur in the given scenario?

A

According to the given scenario, the page becomes vulnerable to a non-persistent (reflected) XSS attack. These types of attacks take place when unvalidated user-provided data is included in the HTML page without HTML entities, and received in response from the server. This is the most common type of XSS attack.

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

Cookie header

A

A cookie is saved as a name=value pair. The name itself is associated with the value of the cookie. A cookie header appears to the browser as follows:

Set-Cookie: name=value; expires=date; path=path; domain=domain; secure

17
Q

Which of the following practices will you use for preventing cross-site scripting (XSS) attacks?

A

As you learned with XSS, creating code that follows proper output encoding and input validation practices (i.e., rigorous syntax standards and checking practices) can protect your site and your users from certain types of attacks. You should not trust user input, and you should always encode output to filter metacharacters; this will help prevent most XSS attacks.