javascript - Parameter Checks as Null/Undefined Despite Console Showing a Value -


i have function references things. purpose of fixing bug, i've removed other case statements (they don't change nor fix problem). have removed return, because that's irrelevant @ stage too.

for reason, pass element in dom: referencer('id', 'hello'), despite chrome console telling me type = 'id' if (type === null || "" || "undefined") fires every single time.

here's jsbin: https://output.jsbin.com/secuciyeko

function referencer(type, value) {      // standard declaration     "use strict";      // open console group     window.console.groupcollapsed("[scriptbase.js]/[referencer] @ " + scriptbase.time());      // log status     window.console.info("[process started @ " + scriptbase.time() + "]");            /* ------- computation ------- */      // local variables     var = null;      // log status     window.console.log("[success @ " + scriptbase.time() + "]: checking unusable values.");      // value validation     if (type === null || "" || "undefined") {          // log status         window.console.error("[failure : " + scriptbase.time() + "] : failure '" + type + "' value '" + value + "'.");          // close console group         window.console.groupend();          // exit method         return;      }     if (value === null || "" || "undefined") {          // log status         window.console.error("[failure : " + scriptbase.time() + "] : failure '" + type + "' value '" + value + "'.");          // close console group         window.console.groupend();          // exit method         return;      }      // log status     window.console.log("[success : " + scriptbase.time() + "] : looking '" + type.touppercase() + "' value of '" + value + "'.");      // value     switch (type) {         case "id":              // variable assignment             = document.getelementbyid(value);              // log status             window.console.log("[success : " + scriptbase.time() + "]: found dom id of '" + value + "'.");              // break case             break;     } } 

with this

if (type === null || "" || "undefined") { 

you saying:

  • if type equal null
  • or if empty string true
  • or if string 'undefined' true

you not comparing type '' or 'undefined'.

you can change to

if (!type) { 

then if empty, null or undefined go in condition.

read about


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -