Course contentsShow
← JavaScript
Lesson 390 of 2,72311. FunctionsFree lesson

Function Naming Conventions

Learn best practices for naming functions clearly and meaningfully.

Function Naming Conventions

You'll learn how to name your functions so they're instantly understandable to anyone reading your code.

Why Function Names Matter

A function is a reusable piece of code that performs a specific task. Its name is the first (and sometimes only) clue about what it does. Good names make code self-documenting; poor names create confusion and force readers to dig through implementation details.

Best Practices for Naming Functions

Use Verbs or Verb Phrases

Functions do something, so start with an action word:

function calculateTotal() { ... }
function sendEmail() { ... }
function validateInput() { ... }

Not: function total() or function email() — these sound like variables, not actions.

Be Descriptive, Not Vague

Choose specificity over brevity:

function getUserById() { ... }     // Clear
function get() { ... }              // Too vague

Use camelCase

JavaScript convention uses camelCase for function names (first word lowercase, subsequent words capitalized):

function formatPhoneNumber() { ... }
function isValidEmail() { ... }

Boolean Functions: Use is/has/can Prefixes

When a function returns true or false, signal that clearly:

function isActive() { ... }
function hasPermission() { ... }
function canEdit() { ... }

Stay Consistent

If you name one function getUser, don't name another retrieveProduct. Pick patterns and stick with them across your codebase.

Key Takeaway: Name functions with clear, verb-based phrases using camelCase — your code should read like plain English, making your intent obvious without needing comments.