什么是“||”除了Or之外在JavaScript中引用?

时间:2016-12-06 11:38:15

标签: javascript

我最近浏览了一些JavaScript代码(由其他人编写),它有类似的内容:

var exports = exports || null;

这是什么意思?这相当于:

var exports = exports ? exports : null;

1 个答案:

答案 0 :(得分:0)

  

除了Or?

之外,JavaScript中的“||”是指什么?

没什么,但它的“或”的定义与其他语言不同。

||运算符计算其左侧操作数,如果该结果是 truthy ,那就是操作的结果;否则,将评估右侧操作数,结果是操作的结果。

因此它不一定会产生布尔值。在您的示例中,exports || null如果它是真实的,则为exports的值,如果不是null则为 <!-- =========================================================== --> <!-- DataSource --> <!-- =========================================================== --> <New id="rfid" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg>jdbc/rfid</Arg> <Arg> <New class="org.apache.tomcat.jdbc.pool.DataSource"> <Set name="driverClassName">oracle.jdbc.OracleDriver</Set> <Set name="url">jdbc:oracle:thin:@integra:1521:integra</Set> <Set name="username">user</Set> <Set name="password">password</Set> <Set name="defaultAutoCommit">false</Set> <Set name="jmxEnabled">true</Set> <Set name="testWhileIdle">false</Set> <Set name="testOnBorrow">true</Set> <Set name="testOnReturn">false</Set> <Set name="validationQuery">SELECT 1 FROM dual</Set> <Set name="validationInterval">30000</Set> <Set name="minEvictableIdleTimeMillis">30000</Set> <Set name="timeBetweenEvictionRunsMillis">30000</Set> <Set name="initialSize">8</Set> <Set name="minIdle">8</Set> <Set name="maxIdle">8</Set> <Set name="maxActive">10</Set> <Set name="maxWait">30000</Set> <Set name="removeAbandonedTimeout">120</Set> <Set name="logAbandoned">true</Set> <Set name="removeAbandoned">true</Set> <Set name="jdbcInterceptors"> org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=2000); org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx; </Set> </New> </Arg> </New> <New id="myphoto" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg>jdbc/myphoto</Arg> <Arg> <New class="org.apache.tomcat.jdbc.pool.DataSource"> <Set name="driverClassName">com.mysql.jdbc.Driver</Set> <Set name="url">jdbc:mysql://localhost:3306/myphotoipb?zeroDateTimeBehavior=convertToNull&amp;useSSL=false</Set> <Set name="username">myphoto</Set> <Set name="password">password</Set> <Set name="defaultAutoCommit">false</Set> <Set name="jmxEnabled">true</Set> <Set name="testWhileIdle">false</Set> <Set name="testOnBorrow">true</Set> <Set name="testOnReturn">false</Set> <Set name="validationQuery">SELECT 1 FROM dual</Set> <Set name="validationInterval">30000</Set> <Set name="minEvictableIdleTimeMillis">30000</Set> <Set name="timeBetweenEvictionRunsMillis">30000</Set> <Set name="initialSize">2</Set> <Set name="minIdle">4</Set> <Set name="maxIdle">8</Set> <Set name="maxActive">10</Set> <Set name="maxWait">30000</Set> <Set name="removeAbandonedTimeout">120</Set> <Set name="logAbandoned">true</Set> <Set name="removeAbandoned">true</Set> <Set name="jdbcInterceptors"> org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=2000); org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx; </Set> </New> </Arg> </New>