Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript : Coding standards, Pascal Casing or Camel Casing? [duplicate]

I am creating calling a function and passing in an array of objects but i am unsure if to use camingCasing or PascalCasing. Here is my method

util.load({
        DefaultText:'Empty',
        Items:[
            {
                Id:0,
                Title:'Press'
            }
        ]
});

If you notice i am passing in DefaulText, but should it be defaultText? and also Items, should it be items? and within the Items and i am also passing in Id and Title.

Can anyone confirm the correct way of doing this?

I know that methods are camelCasing but passing in objects like above?

Thanks in advance

like image 479
Martin Avatar asked Dec 13 '22 04:12

Martin


2 Answers

The very popular JavaScript convention is to use PascalCasing as you call it for constructors (classes), for example String, Number, Date and camel casing for variable names and object keys. This code convention is used for all the built-in JavaScript functionality in the modern browsers, so thats why I would recommend to use it for your own code too.

like image 140
bjornd Avatar answered Dec 15 '22 01:12

bjornd


There is no one correct way.

The JavaScript API uses camelCase for functions and PascalCase for objects.

Just choose one and be consistent. JavaScript identifiers are case sensitive.

like image 32
alex Avatar answered Dec 15 '22 00:12

alex