Home  >  Article  >  Backend Development  >  赋值查询到变量和直接使用查询有什么区别?

赋值查询到变量和直接使用查询有什么区别?

WBOY
WBOYOriginal
2016-06-06 16:44:20812browse

如题,赋值查询到变量和直接使用查询有什么区别?

// 代码一
var a = getCookie('username');
if( a==null || a=='' ) var m = 'empty';
// 代码二
if( getCookie('username')==null || getCookie('username')=='' ) var m = 'empty';

回复内容:

事实上就是你说的那样 事实上和题主说得一样,后面一个可能会引起强迫症人士的强烈不适…… -0- 事实如你所说一样。 1.性能,不过这个例子不明显,查数据库就明显了。
2.可读性,明显第二条你要花多一点时间去看 || 前后两个变量是怎么回事,第一段代码一眼就看出来这两个是同一个变量。 降低耦合?

这里不明显,如果涉及到读取数据库的话,就知道有啥用了。(轻喷 事实上:代码一调用一次,代码二调用两次。第一种方式效率稍微高一点。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn