Week - 5 Flashcards
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?
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.
CODE:
…
document.addEventListener(“DOMContentLoaded”, function(event) {
console.log(“Yey!”);
});
…
<h1>Hello!</h1>
It will output Yey! when the web page is loaded, but before external resources like images are downloaded to the user’s machine.
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.
True
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?
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.
Another name for Object Literal is JSON.
False
JSON is a string, Object Literal is a way of creating a real object in Javascript.
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 }'
Option 3 as single quotes are not allowed in JSON.