ITeye博客

Read OO JS

wangdun119 · 2012-03-23 17:34 · JavaScript · Web前端 · Markdown

Most values convert to true with the exception of the following (which convert to false): **

  1. The empty string ""
  2. null
  3. undefined
  4. The number 0
  5. The number NaN
  6. The boolean false ** These six values are sometimes referred to as being falsy, while all others are truthy

This example also shows another interesting behavior—if JavaScript encounters a non-boolean expression as an operand in a logical operation, the non-boolean is returned as a result.

true || "something" true true && "something" "something"

Deleting Elements In order to delete an element, you can use the delete operator. It doesn't actually remove the element, but sets its value to undefined. After the deletion, the length of the array does not change.

var a = ; delete a; true a

Understanding these topics will provide a solid base that will allow you to dive into the second part of the chapter, which shows some interesting applications of functions:

Using anonymous functions Callbacks Self-invoking functions Inner functions (functions defined inside functions) Functions that return functions Functions that redefine themselves Closures

Function

1.Using argument


function sumOnSteroids() {
var i, res = 0;
var number_of_params = arguments.length;
for (i = 0; i < number_of_params; i++) {
res += arguments[i];
}
return res;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。