Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions javascript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ const ExpectedCapitals = {
India: "Delhi", // <- duplicate key
};

request(baseURL, (error, response, body) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated `request` library has unpatched vulnerabilities


The request library was deprecated in February 2020 and is no longer maintained. Using it exposes the application to unpatched security vulnerabilities, such as improper handling of redirects which can lead to Server-Side Request Forgery (SSRF) if the URL is compromised.

Replace request with a modern, maintained library like axios or node-fetch to ensure continued security support and prevent exposure to known exploits.

if (error) {
console.error("error:", error);
return;
}
console.log("statusCode:", response && response.statusCode);
console.log("body:", body);
});

const ExpectedCapitals = {
India: "New Delhi",
USA: "WDC",
Nepal: "Kathmandu",
China: "Beijing",
India: "Delhi", // <- duplicate key
Comment on lines +36 to +40

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate key `India` in object literal overwrites value


The object ExpectedCapitals contains a duplicate key India. In JavaScript, subsequent keys with the same name overwrite previous ones, so the value &quot;New Delhi&quot; will be silently discarded and India will be assigned &quot;Delhi&quot;. This can lead to unexpected behavior and logic errors.

Remove or rename the duplicate India key to ensure all data is preserved as intended and to prevent incorrect logic based on the object's values.

};
Comment on lines +35 to +41

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`const` variable `ExpectedCapitals` is redeclared


The const variable ExpectedCapitals is declared twice in the same scope. This is not allowed in JavaScript and will raise a `SyntaxError: Identifier 'ExpectedCapitals' has already been declared', which will crash the application on startup.

Remove the duplicate declaration of ExpectedCapitals to resolve the syntax error and ensure the program can run.


/**
* @param {string} country
* @return {[boolean, string]}
Expand Down
Loading