JavaScript Others
1. How do you find operating system details
console.log(navigator.platform);
2. What are the tools or techniques used for debugging JavaScript code
Chrome Devtools (F12)
debugger statement
Good old console.log statement
3. What is same-origin policy
The same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).
4. What is the purpose of void 0
Void(0)
is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML documents that use href="JavaScript:Void(0);"
within an <a>
element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression. For example, the below link notify the message without reloading the page.
<a href="JavaScript:void(0);" onclick="alert('Well done!')">
Click Me!
</a>