In order to make sure my site works for a user I need to check that both JSON and XMLHttpRequest() are defined as objects by their browser. Rather than if/else I thought I'd use the ternary operator:
condition ? true : false.
I tried the following and it doesn't work correctly. Firstly, the following alerts "Success":
(typeof(JSON) && typeof(XMLHttpRequest()) == "object" ? window.alert("Success") : window.alert("Fail"));
...which is all good until I try:
(typeof(JSONsdsdsd) && typeof(XMLHttpRequest()) == "object" ? window.alert("Success") : window.alert("Fail"));
...which should have alerted "fail". I then try:
(typeof(JSON) && typeof(XMLHttpRequestghfh()) == "object" ? window.alert("Success") : window.alert("Fail"));
...which results in no alert box coming up.
I'd be grateful if someone with more experience could point out where I've gone wrong. Thanks in advance for any help/tips/pointers :)