Hello! Today I decided to blog on an article about JavaScript tips. JavaScript is an essential programming language for web development, so I decided to share these tips in case I ever need a reference.
Navigation tool
Browser OS details can be viewed by using either the window.navigator object or navigator.platform method.Stopping Auto Refresh
void(0) prevents the page from auto-refreshing.Page Redirecting
The user can be redirected to a new page by setting the href property of the location object, which is a property of the window object.
function redirect() {
window.location.href = "newPage.html";
}Email Validation
function validateEmail(email) {
var re =
/^(([^<>()[]\.,;:\s@"]+(.[^<>()[]\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}Fetching URL
window.location.href can be used to get the current URL and update it.Getting metadata
The import.meta object contains information on the current module.
This post was inspired by:
Baranwal, A. (2024, July 1) 15 Amazing JavaScript Tips
Retrieved from: [https://dev.to/anmolbaranwal/15-amazing-things-you-can-do-with-simple-javascript-g88?context=digest]
Top comments (0)