mlissner
mlissner

Reputation: 18186

Why can't I assign location.hash to a variable?

Why is it that I can get the value of location.hash when I call it like so:

> location.hash
"#my-hash-value"

But when I call it like so, it's undefined:

> var foo = location.hash
undefined

I'm missing something obvious. This is in Firefox.

Upvotes: 0

Views: 112

Answers (1)

Mindbreaker
Mindbreaker

Reputation: 1025

The Statement doesn't return a value, but the variable is set. Try

console.log(a)

Upvotes: 2

Related Questions