JS Array vs [], and whether or not NULL is judged

Source: Internet
Author: User
Tags javascript array

The two are basically the same, and the only difference is initialization:

varA = [],//These is the sameb =NewArray (),//A and B is arrays with length 0C= [' foo ', ' Bar '],//These is the sameD =NewArray (' foo ', ' Bar '),//C and D is arrays with 2 strings//these is different:e = [3]//E.length = = 1, e[0] = = 3f =NewArray (3),//F.length = = 3, f[0] = = undefined

That is, array (ARG), where Arg refers to the length of the generated array.

Reference: What'sthe difference between "array ()" and "[]" while declaring a JavaScript array?

Check if the array is empty:

if (Array = = = Undefined | | array.length = = 0)    {//  array empty or does not exist}

JS Array vs [], and whether or not NULL is judged

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.