Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Conventions JS References JS Versions

JS HTML

JS HTML DOM JS Events JS Projects

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Function Parameters

Parameters (Function Input)

Parameters allow you to pass (send) values to a function.

Parameters are listed inside the parentheses in the function definition.

Example

function multiply(a, b) {
  return a * b;
}

let result = multiply(4, 5);
Try it Yourself »

Functions with One Parameter

A function can have one parameter.

Examples

function sayHello(name) {
  return "Hello " + name;
}

let greeting = sayHello("John");
Try it Yourself »
function toCelsius(fahrenheit) {
  return (5 / 9) * (fahrenheit - 32);
}

let value = toCelsius(77);
Try it Yourself »

Functions with Multiple Parameters

You can add as many parameters as you want, separated by commas.

Example

function fullName(firstName, lastName) {
  return firstName + " " + lastName;
}

let name = fullName("John", "Doe");
Try it Yourself »


Parameters vs. Arguments

In JavaScript, function parameters and arguments are distinct concepts:

Parameters are the names listed in the function definition.

Arguments are the real values passed to, and received by the function.


Parameter Rules

JavaScript function definitions do not specify data types for parameters.

JavaScript functions do not perform type checking on the arguments.

JavaScript functions do not check the number of arguments received.


Incorrect Parameters

Accessing a function with an incorrect parameter can return an incorrect answer:

Example

function toCelsius(fahrenheit) {
  return (5/9) * (fahrenheit-32);
}

let value = toCelsius();
Try it Yourself »

Default Parameter Values

ECMAScript 2015 allows function parameters to have default values.

The default value is used if no argument is provided.

Example

If y is not passed or undefined, then y = 10.

function myFunction(x, y = 10) {
  return x + y;
}
myFunction(5);
Try it Yourself »

Next Chapter

Function Return Values



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->