What does "typeof window == 'undefined' " mean?

ritaaudi
Tera Contributor

Hi: We have the following script in our 'Resolve Now' UI action that is called every time the user clicks the 'Resolve Now' button:

if (typeof window == 'undefined') {

  serverResolve();

}

I am wondering if something is wrong with the code. What is window == 'undefined'? Is it always 'undefined'? When is it 'defined'?

Thanks for your help!

Rita

1 ACCEPTED SOLUTION

Hi Rita,  



if(typeof window == 'undefined') means



1.Code that runs without 'onclick'.


2.Ensure call to server-side function with no browser errors


View solution in original post

10 REPLIES 10

ABHISHEK PORWA1
Tera Contributor

if we write 
var name = "servicenow"
gs.print(typeof name ) , It will give string because typeof name is string.

Similar window has all the components within it, so the type of will always be undefined and your server side code will execute.

By doing this we will eliminate the change of brower errors which may occur while doing both server and client action in one script frame