# How to check for a hash in URL using JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 30, 2022. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-check-hash-in-url

> Learn how to use the window.location property to check if the URL contains a hash or fragment component in JavaScript.

You can use the `window.location` &mdash; the location property of the window &mdash; to check if the URL contains a hash (`#`) or fragment component in JavaScript.

The `window.location` is a read-only property that returns [the `Location` object](https://attacomsian.com/blog/javascript-location-object) representing the current URL of the document being displayed.

The `hash` property of the `Location` object returns a string containing a `#` followed by the fragment identifier of the URL. 

Here is an example that checks if the URL contains a hash or not:

```javascript
let hash = window.location.hash
if (hash) {
  console.log(`URL contains a hash!!`)
} else {
  console.log(`URL does not contain a hash!!`)
}
```
