/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Detecting the existence of a parameter /* Example 1: The in operator Detect whether there is a "myparameter" member in the "oArg" object: */ var myparameter = 'myparameter' in oArg? oArg.myparameter : ""; /* Example 2: The typeof operator Detect whether type of oArg.myparameter is not "undefined': */ var myparameter = typeof oArg.myparameter != 'undefined'? oArg.myparameter : ""; /* Example 2.1: The typeof operator version 2 Assuming parameter is a string, detect whether type of oArg.myparameter is "string": */ var myparameter = typeof oArg.myparameter == 'string'? oArg.myparameter : ""; /* Example 3: Autocasting Assign the value of oArg.myparameter to variable "myparameter" if it casts to true: */ var myparameter = oArg.myparameter || "";