Does a matter whether a value is primitive or boxed

后端 未结 3 486
眼角桃花
眼角桃花 2021-01-01 20:49

One can use typeof to determine whether a value is primitive or boxed.

Consider:

typeof \"foo\"; // \"string\"
typeof new String(\"foo\         


        
3条回答
  •  迷失自我
    2021-01-01 20:59

    I use underscore.js methods to detect the type of the variable. Try to use: isEmpty, isElement, isArray, isArguments, isFunction, isString, isNumber, isBoolean, isDate, isRegExp isNaN, isNull, isUndefined

    Described here: http://documentcloud.github.com/underscore/

提交回复
热议问题