Home 在js中判断ruby的.present?
Post
Cancel

在js中判断ruby的.present?

直接用if就可以. 

参考: http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in

if( value ) {
}

will evaluate to true if value is not:

null
undefined
NaN
empty string ("")
0
false

 ps. 其实这么死扣语法的事情,我是不喜欢的.  特别是: 

if(typeof variable==='undefined' || variable===null) {

/* do your stuff */
}
This post is licensed under CC BY 4.0 by the author.