Home  >  Article  >  Web Front-end  >  javascript short circuit method code streamlining_javascript skills

javascript short circuit method code streamlining_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:47:58901browse

I encountered a piece of code as follows
if(n>win) {
p=dArry.length-win;
}
else if(np=0;
}
else {
p=n;
}
There are many similar codes. Let’s continue to simplify. It’s actually very simple. It becomes like this
p=((n>win)&&( dArry.length-win))||((nTo summarize: && takes the last value, || takes the first satisfying value, efficient, but please use it flexibly

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