`

Read OO JS

 
阅读更多
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 = [1, 2, 3];
>>> delete a[1];
true
>>> a
[1, undefined, 3]


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;
}











分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics