0

This line:

if(Debug===true){console.log('No jquery detected on host site, loading own jquery');}

Is breaking my script in a nokia windows phone, if I set that variable to false, everything works nicely, but if set to true the script stops. I tried also putting an alert instead of that console.log but same stop behaviour.

Anybody knows or suspects something about the reason of such behaviour?

EDIT

Tks for all the replies, the fact is that if I take out the entire console.log line and inside the if for example I leave it empty or i put a simple var declaration same stop behaviour remains, It makes me suspect is more related with the if statement than with the console object

2nd EDIT

As you all said is a fact, the console.log breaks it, I had a hidden one, found it and now works, so no relation to the if instead all the fault from the console object, tkyou all

Santiago Rebella
  • 2,399
  • 2
  • 22
  • 29

5 Answers5

4

I would not rely on the console object existing on a windows phone. You should bullet-proof your statement to make sure it doesn't blow up:

if (Debug===true && typeof console !== 'undefined') {
    console.log('No jquery detected on host site, loading own jquery');
}
jbabey
  • 45,965
  • 12
  • 71
  • 94
2

Console.Log and Alert are not supported on WP7. Are you sure this is Nokia specific and not just WP7 specific? I haven't tried it, but this library might be useful.

keyboardP
  • 68,824
  • 13
  • 156
  • 205
1

Hmm, this is strange. I am not entirely sure why you are using if(Debug===true) instead of if(Debug) or even if(debug==true). === are unnecessary for boolean. You may want to try that an see if it corrects your problem.

Andrew Rhyne
  • 5,060
  • 4
  • 28
  • 41
  • tks, I tried already also only with if(Debug){} but same issue – Santiago Rebella Oct 09 '12 at 13:57
  • 1
    `if(Debug)` will pass as long as `Debug` is any "truthy" value. `if(Debug===true)` will only pass if `Debug` is, in fact, `true`. These are two very different conditions. – jbabey Oct 09 '12 at 15:15
  • It only really matters if you are working with a poor design. If the software is designed properly, you should know all of the possible values that are going through this logic gate. So there is no need to say if(debug===true). It's just less readable. If(Debug) works fine, unless you plan on using Debug for a variety of different value types (other than just boolean or empty) which is bad programming practice anyway. – Andrew Rhyne Oct 10 '12 at 19:07
  • If debug is empty, its false. if debug is false, its false. if debug is true, its true. I fail to see any other situation involved with an obviously boolean variable. @SantiagoRebella, to answer your original question, is this the only boolean logic gate that is causing failures? Are other similarly written statements doing the same thing? Is there ever a time where debug isn't initialized? The windows phone JS engine handles that different. – Andrew Rhyne Oct 10 '12 at 19:09
1

Don't rely on console.log existing. If you're going to use it check that it is defined first.

Matt Whipple
  • 7,034
  • 1
  • 23
  • 34
1

I believe older versions of Internet Explorer don't define console by default. You can check if console is defined by doing so:

if(Debug===true){
    if(!!console){
        console.log('No jquery detected on host site, loading own jquery');
    } else {
        window.console = { log: function(m){ alert(m); } } //Define console to prevent future errors.
        alert('No jquery detected on host site, loading own jquery');
    }
}
Rémi Breton
  • 4,209
  • 2
  • 22
  • 34