DEV Community

Christopher Chhim
Christopher Chhim

Posted on

JavaScript Tips

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]

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay