Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "-[1, ]" mean in " if(!-[1, ] && !window.XMLHttpRequest)"?

Tags:

javascript

I find the code below , but I can't understand this.

if (!-[1, ] && !window.XMLHttpRequest) {
    document.execCommand("BackgroundImageCache", false, true);
}

What does if(!-[1,]) mean ? Thanks

like image 260
acjialiren Avatar asked Jul 27 '12 06:07

acjialiren


People also ask

What does [- 1 :] mean in Python?

Python also allows you to index from the end of the list using a negative number, where [-1] returns the last element. This is super-useful since it means you don't have to programmatically find out the length of the iterable in order to work with elements at the end of it.

What is a [:- 1 in python?

Artturi Jalli. In Python, [::-1] means reversing a string, list, or any iterable with an ordering. For example: hello = "Hello world" nums = [1, 2, 3, 4]

What does 1 mean in JavaScript?

It means "subtract one from the previous value". Same thing it always means. Possibly you intended to ask "why is it there?" In that case, the answer is that JavaScript arrays are zero-indexed, which means the last index in the array is one less than the length of the array (because the first index is 0, not 1).


1 Answers

It's a hack to detect old Internet Explorer. -[1,] is -1 in modern browsers (so false with !) but NaN in old IE (true negated). The first version to return correct result is IE9.

like image 136
duri Avatar answered Oct 22 '22 21:10

duri