Question
What will be the output of the following JavaScript code
when executed? let xhr = new XMLHttpRequest(); xhr.open("GET", "https://api.example.com/data", false); xhr.send(); console.log(xhr.responseText);Solution
In this JavaScript code, an XMLHttpRequest object (xhr) is created to send a synchronous GET request to the specified URL. The open method initializes the request, with the third parameter set to false, making the request synchronous. This means that the script will pause execution until the server responds. When xhr.send() is called, the request is sent, and upon completion, xhr.responseText contains the server's response, which is printed to the console. Why Other Options Are Wrong: B) An error due to using a synchronous request: This option is incorrect because while synchronous requests can lead to performance issues (blocking the UI), they do not inherently cause errors unless there are issues with the request itself. C) undefined: This option is incorrect because the responseText will contain the server's response if the request is successful, rather than being undefined. D) The text "GET request was successful": This option is incorrect as it does not reflect a specific response from the server; the actual response depends on the API being called. E) The server's HTML code: This option may be misleading; while itβs possible the server could return HTML, the actual output depends on the response from the specific API being called.
- As of February 2025, how many railway stations across India had installed solar power plants?
Which ministry is organising the SOAR β Skilling for AI Readiness programme?
What event did Ekta Bhyan qualify for with an Asian record in club F51 at the Dubai World Para Athletics GP?
I. World Para swimming championships...
How much did Hockey India announce as a reward per player for winning the Asia Cup hockey 2025?
Under the Namo Drone Didi Scheme, what percentage of the drone cost is subsidized, and what is the maximum subsidy amount available per drone?
...Blanka VlaΕ‘iΔ, appointed as International Event Ambassador for TCS World 10K Bengaluru 2026, is associated with which sport?
Which Indian cricketer was awarded honorary membership by the Melbourne Cricket Club (MCC)?
What is the theme of the 4th India-Africa Forum Summit (IAFS-IV)?
What is the name of the upgraded youth engagement platform developed under the MoU between the Ministry of Youth Affairs and Sports and Digital India Co...
Under the PRARAMBH 2026 initiative, the number of rules has been reduced from 510 to: