我正在使用angularjs 1.4.3。我有一种好奇心,因为我不了解Jasmine Spec Runner生成的代码代码。
当我们生成它时,Jasmine(通过ChutzPath)创建此代码:
class CreateLineItems < ActiveRecord::Migration
def change
create_table :line_items do |t|
t.string :name
t.decimal :price, precision: 8, scale: 2
t.timestamps null: false
end
end
end
如果(&#34;&#34;)是什么?我知道这个愚蠢的问题,但我不理解
可能是if(true)还是if(1)?
答案 0 :(得分:2)
如您所知,if
语句中的代码在其条件调整为布尔true
时执行。如果条件没有返回布尔值,则javascript使用Type Coercion将条件解释为布尔值。您可以在此处阅读有关类型强制的更多信息:
What exactly is Type Coercion in Javascript?
提供真实/错误值的文章,在这里提供了类型强制时不同类型的数据:
https://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
引用您案件中的相关部分:
条件
在JavaScript中,所有条件语句和运算符都遵循相同的强制范式。我们将通过示例的方式使用if语句。
构造if(Expression)Statement将使用抽象方法ToBoolean将Expression的计算结果强制转换为布尔值,ES5规范定义了以下算法:
Argument Type Result Undefined false Null false Boolean The result equals the input argument (no conversion). Number The result is false if the argument is +0, −0, or NaN; otherwise the result is true. String The result is false if the argument is the empty String (its length is zero); otherwise the result is true. Object true.