Function & Classes Naming Convention
Function naming convention
Function's names are formatted in camelCase notation. It’s a best practice to include the verb as a prefix in the function name that tells the purpose of the function.
In JavaScript function is just like a procedure or collection statements of calculating a value or perform a task. We will learn about the functions in detail in the later sections.
1234567// Descriptive name of function function getName(firstName, lastName) { return `${firstName} ${lastName}`; } const myName = getName('Bob','William'); console.log(myName);
Classes naming convention:
Class is declared with a PascalCase. Class is like a template for creating objects. They encapsulate data with code to work on that data. We will study the classes in detail in later sections.
123456789class WebDeveloper { constructor(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } } const robinWieruch = new WebDeveloper('Robin', 'Wieruch'); console.log(robinWieruch);
Note:
Classes are very advanced topics and will be covered later, so no exercises for this topic for now.
Summary:
- Naming convention purpose logic in your code. It is the standard in the JS community.
- Variables are case-sensitive.
- Constants are written in UPPERCASE (capital letters).
- Prefixes are added in the booleans for clarity.
- Functions names are formatted in camelCase notation.
- Class is declared with a PascalCase.
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Can you explain the difference between camelCase and PascalCase?
Why are prefixes added to boolean variables?
Can you give more examples of function and class naming conventions?
Fantastisk!
Completion rate forbedret til 2
Function & Classes Naming Convention
Sveip for å vise menyen
Function naming convention
Function's names are formatted in camelCase notation. It’s a best practice to include the verb as a prefix in the function name that tells the purpose of the function.
In JavaScript function is just like a procedure or collection statements of calculating a value or perform a task. We will learn about the functions in detail in the later sections.
1234567// Descriptive name of function function getName(firstName, lastName) { return `${firstName} ${lastName}`; } const myName = getName('Bob','William'); console.log(myName);
Classes naming convention:
Class is declared with a PascalCase. Class is like a template for creating objects. They encapsulate data with code to work on that data. We will study the classes in detail in later sections.
123456789class WebDeveloper { constructor(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } } const robinWieruch = new WebDeveloper('Robin', 'Wieruch'); console.log(robinWieruch);
Note:
Classes are very advanced topics and will be covered later, so no exercises for this topic for now.
Summary:
- Naming convention purpose logic in your code. It is the standard in the JS community.
- Variables are case-sensitive.
- Constants are written in UPPERCASE (capital letters).
- Prefixes are added in the booleans for clarity.
- Functions names are formatted in camelCase notation.
- Class is declared with a PascalCase.
Takk for tilbakemeldingene dine!
single