What is the correct use of the "in" operator, in javascript?

8

This code does not return anything, why? I'm running in event "window.onload":

if(innerHeight in window){
     console.log('true');
}

I had used the operator again and again, and it worked, but now it came to me ... And then, can anyone help me here?

    
asked by anonymous 15.02.2017 / 07:35

1 answer

9
'innerHeight' in window

As you are looking for a property you should use a String , otherwise it is as if you were searching for the contents of the variable innerHeight in window , that is what you have is: p>

var alturaEmPixeis = windows.innerHeight; // isto é um numero
if (alturaEmPixeis in window){

And you should have

if ('innerHeight' in window){

to know if the object window has the name property innerHeight .

    
15.02.2017 / 07:39