Javascriptが難しくてわからないので誰か教えてください

僕はプログラミングがまったくわからないので誰か教えて欲しいのですが、

> []
[]
> [,]
[]
> [,,]
[]

空配列です。なんというか空配列ですね。

> [].toString()
""
> [,].toString()
""
> [,,].toString()
","

いやー、カンマがいっぱいでなんだか楽しい気分です。カ、ン、マ、カンマ、カ、ン、マ!(歌は気にするな!というアンクちゃんの声が聞こえますね。ろーじーちゃん嬉しい)

それで、僕はよくわからないままTwitterに助けを求めた所、undefinedが入っているみたいだよみたいなことを言われましたが、評価した限り、空配列です。なんだかよくわからなくなってきました。ふしぎの海のナディア!

誰かどういうことかまともに説明してください!


This entry was posted in Programming and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted 2011/05/14 at 06:18 | Permalink

    [].length 0 [,].length 1 [,,].length 2 だからではないかと。 つまり [] は本当に [] [,] は [undefined] [,,] は [undefined, undefined] だから toString() したときにそうなるのではないでしょうか。

  2. Posted 2011/05/14 at 14:18 | Permalink

    この現象は、JavaScript の配列リテラルの仕様と、処理系の省略表示が原因です。 解説記事を書いてみたので、よろしければ見てみてください。 http://seaoak.cocolog-nifty.com/read/2011/05/post-df49.html

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>