Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Javascript Check if a url query string exists display it on the page


//create a function that takes a url query string as an argument
function checkQueryString(url) {
  //check if the url query string exists
  if (url.indexOf("?") !== -1) {
    //if it exists display it on the page with comments
    console.log("The query string exists.");
  } else {
    //if it does not exist display it on the page with comments
    console.log("The query string does not exist.");
  }
}

//example
const url = "https://www.codecademy.com/learn";
checkQueryString(url);

//output
//The query string exists.


Enter fullscreen mode Exit fullscreen mode

Top comments (0)