---
title: "JavaScript Comma Operator"
author: "deng131"
date: "2011-04-04T16:34:40Z"
tags: []
categories: ["Web前端"]
slug: "javascript-comma-operator"
draft: false
lastmod: "2011-04-04T16:35:07Z"
id: 986189
url: "https://thinking80s.iteye.com/blog/986189"
---

记得以前面试时候遇到过类似问题： js中','操作符优先级问题。

```java

//original
var a = (7, 5);
//apply group
var a = 5;
```



```java
for ( var i=2, r=[0,1]; i<15; r.push(r[i-1] + r[i-2]), i++);{} 
r //"0,1,1,2,3,5,8,13,21,34,55,89,144,233,377"
```

同时页比较了使用 && 和 || 不同
//(LHE: left hand expression, RHE right hand expression)

LHE && RHE
1. Always evaluate LHE
2. If LHE is true, evaluate RHE

LHE || RHE
1. Always evaluate LHE
2. If LHE is false, evaluate RHE

LHE, RHE
1. Always evaluate LHE
2. Always evaluate RHE

英文比较好理解。
<http://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/#comment-2422>