JavaScript Tips

Christopher Chhim - Jul 11 - - Dev Community

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.

  1. Navigation tool
    Browser OS details can be viewed by using either the window.navigator object or navigator.platform method.

  2. Stopping Auto Refresh
    void(0) prevents the page from auto-refreshing.

  3. 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";
    }

  4. 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());
    }

  5. Fetching URL
    window.location.href can be used to get the current URL and update it.

  6. 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]

. . . . . . . . . . . . . . . . . . . . . . . . . . .