Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window object not exist but still exists in NodeJS

Tags:

node.js

if(typeof window !== undefined) {
  console.log("this should print only if window object actually exists")
}

Can somebody tell me why NodeJS (0.6.5) is not working correctly when checking if window is not defined? If you call typeof window, you get undefined but still condition above fails to work. Any ideas?

like image 765
jimmy Avatar asked Dec 27 '22 05:12

jimmy


1 Answers

if(typeof window !== 'undefined') {
  console.log("this should print only if window object actually exists")
}

typeof returns a string

like image 192
Damp Avatar answered Jan 07 '23 06:01

Damp