开发者

Does this create an array in JavaScript?

I am using the following JavaScript code:

var a = [23, 34, 45, 33];

Is a con开发者_StackOverflow社区sidered an array of integers?


Yes, a is an array. However, since Javascript isn't statically typed, it can contain other types as well, such as strings, objects, other arrays and so on. Therefore, tagging it as "an array of integers" wouldn't be right.


JavaScript doesn't have an Integer type. It is an Array containing Numbers (but not limited to containing only Numbers)


You are creating an array a using an array literal.

An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ([]). When you create an array using an array literal, it is initialized with the specified values as its elements, and its length is set to the number of arguments specified.

As the other answers already pointed out, JavaScript arrays are able to contain elements of different data types.


Yes, it is. It really is.


Interesting question...

a is considered an array of integers as long as you want it that way since javascript is dynamically typed, ie. you could potentially do:

var a = [23, 34, 45, 33]; alert(a[0] + 1); // shows 24

a = "sometext"; alert(a + 1); // shows "sometext1"

HTH.


Javascript supports var so you can have combination of string, int, decimal here.

To check further details see this link http://javascript.blogsome.com/category/1/javascript-array/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜