Week - 5 Flashcards

1
Q

HTML:

JS 1:
console.log(document.getElementById(“name”).value
+ “ Coursera!”);
JS 2:
console.log(document.querySelector(“#name”).value
+ “ Coursera!”);
What will be the difference in the output between the 2 Javascript code snippets?

A

No difference
Both methods are valid. The querySelector method expects a CSS query, so the ‘#’ sign is therefore needed before referencing a value of an ‘id’ attribute.

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

CODE:

document.addEventListener(“DOMContentLoaded”, function(event) {
console.log(“Yey!”);
});

<h1>Hello!</h1>

A

It will output Yey! when the web page is loaded, but before external resources like images are downloaded to the user’s machine.

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

One of the differences between a GET request and POST is that a GET request passes query parameters as part of the URL whereas POST request passes them as part of the body of the request.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
JS:
var name = "";
// Making an Ajax call here, i.e., sendGetRequest
$ajaxUtils.sendGetRequest("someURL", function (request) {
  name = "Coursera";
});

document.querySelector(“#content”).innerHTML = name;
What will be the contents of the element with the ‘id’ value of ‘content’ after the execution of this Javascript code?

A

It will be empty.
The setting of the ‘name’ to ‘Coursera’ will happen AFTER the assigning of innerHTML when the ‘name’ variable still contains an empty string.

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

Another name for Object Literal is JSON.

A

False

JSON is a string, Object Literal is a way of creating a real object in Javascript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
Identify invalid JSON string below:
1. '{
  "courseName": "Coursera",
  "startingNumberOfStudents": 12500
}'
2. '{
  "courseName": "Coursera",
  "studentsLoveCourse": true
}'
3. '{
  'courseName': "Coursera",
  'startingNumberOfStudents': 12500
}'
4. '{
  "courseName": {"name": "Coursera"},
  "startingNumberOfStudents": 12500
}'
A

Option 3 as single quotes are not allowed in JSON.

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