Although JavaScript does not enforce, or even recommend, naming conventions it is really useful to have some, and get into the habit of using them. When reading a section of program it can make it so much clearer, showing the kinds of things we are dealing with.
I recommend the following.
const
or not. Thus: NO_OF_COLUMNS
. Note the use of underscores to separate words.card
. If there are multiple words begin subsequent ones with capitals. Thus: aceOfClubs
. This is often referred to as "camel case" because it seems to have humps.Card
(distinguished from card
, which is a variable and probably of type Card
). Type names tend to be single words but if they are multiple then continue in camel case.To further explain the use of object types we will see examples like this in the following pages:
We define the type Card
with a function that sets property values:
function Card (suit, value)
{
this.suit = suit;
this.value = value;
}
Functions like this which define object types have names beginning upper case. All other plain functions or methods will be named like variables, starting small.
Then objects of type Card
are constructed with the new
operator and can be assigned to a variable like this:
var card = new Card (CLUBS, 9);
The variable then holds a reference to the object, somewhere in memory.
(Yes, I still use var
rather than let
. It is more flexible and I have no problem with it. I would not use it for global variables though: I prefer to have just one global const
to hold anything I need to be global, such as GAME
. If you would rather use let
wherever I use var
, that's fine.)