Javascript - Detecting Parameters


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Detecting the existence of a parameter
  2. /*
  3. Example 1: The in operator
  4. Detect whether there is a "myparameter" member in the "oArg" object: */
  5. var myparameter = 'myparameter' in oArg? oArg.myparameter : "";
  6. /*
  7. Example 2: The typeof operator
  8. Detect whether type of oArg.myparameter is not "undefined': */
  9. var myparameter = typeof oArg.myparameter != 'undefined'? oArg.myparameter : "";
  10. /*
  11. Example 2.1: The typeof operator version 2
  12. Assuming parameter is a string, detect whether type of oArg.myparameter is "string": */
  13. var myparameter = typeof oArg.myparameter == 'string'? oArg.myparameter : "";
  14. /*
  15. Example 3: Autocasting
  16. Assign the value of oArg.myparameter to variable "myparameter" if it casts to true: */
  17. var myparameter = oArg.myparameter || "";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.