1/16/26, 5:39 PM JavaScript Function Parameters
Tutorials References Exercises Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
JavaScript Function Parameters
❮ Previous Next ❯
Parameters and Arguments
Parameters allow you to pass (send) values to a function.
Parameters are listed inside the parentheses in the function definition.
Arguments are the real values passed to, and received by the function.
Example
function multiply(a, b) {
return a * b;
}
let result = multiply(4, 5);
[Link] 1/10
1/16/26, 5:39 PM JavaScript Function Parameters
Try it Yourself »
Tutorials References Exercises Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Function parameters are the names listed in the function definition.
Function arguments are the real values passed to (and received by) the function.
In the example above:
a and b are parameters
4 and 5 are arguments
The argument 4 is assigned to the parameter a.
The argument 5 is assigned to the parameter b.
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 »
[Link] 2/10
1/16/26, 5:39 PM JavaScript Function Parameters
Functions
Tutorials with Multiple
References ExercisesParameters
Sign In
HTML
You canCSS
add as JAVASCRIPT SQL
many parameters as youPYTHON JAVA by commas.
want, separated PHP HOW TO [Link] C
Example
function fullName(firstName, lastName) {
return firstName + " " + lastName;
}
let name = fullName("John", "Doe");
Try it Yourself »
The Order of Arguments Matters
Arguments are assigned to parameters in the order they appear.
Example
function subtract(a, b) {
return a - b;
}
let x1 = subtract(10, 5);
let x2 = subtract(5, 10);
Try it Yourself »
The two calls above return different results because the order is different.
[Link] 3/10
1/16/26, 5:39 PM JavaScript Function Parameters
Incorrect
Tutorials Parameters
References Exercises Sign In
HTML CSSa function
Accessing JAVASCRIPT SQLparameters
with incorrect PYTHON JAVAan incorrect
can return PHP HOW TO
answer: [Link] C
Examples
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
let value = toCelsius("John");
Try it Yourself »
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
let value = toCelsius();
Try it Yourself »
Accessing a function without (), returns the function itself and not the result:
Example
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
let value = toCelsius;
Try it Yourself »
[Link] 4/10
1/16/26, 5:39 PM JavaScript Function Parameters
Tutorials References Exercises Sign In
HTML
NoteCSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
In the examples above:
toCelsius refers to the function itself.
toCelsius() refers to the function result.
Missing Arguments
If a function is called with fewer arguments than parameters, the missing values become
undefined.
Example
function multiply(a, b) {
return a * b;
}
multiply(4);
In the example above, b is undefined, so the result is NaN.
Note
A JavaScript function does not perform any checking on parameter values (arguments).
Parameter Rules
JavaScript function definitions do not specify data types for parameters.
JavaScript functions do not perform type checking on the passed arguments.
[Link] 5/10
1/16/26, 5:39 PM JavaScript Function Parameters
JavaScript functions do not check the number of arguments received.
Tutorials References Exercises Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
Default Parameters
If a function is called with missing arguments (less than declared), the missing values are
set to undefined .
Sometimes this is acceptable, but sometimes it is better to assign a default value to the
parameter:
Example
function myFunction(x, y) {
if (y === undefined) {
y = 2;
}
}
Try it Yourself »
Default Parameter Values
You can set a default value for a parameter.
This value is used if no argument is provided.
Example
function greet(name = "Guest") {
return "Hello " + name;
}
greet();
greet("Anna");
[Link] 6/10
1/16/26, 5:39 PM JavaScript Function Parameters
Functions
Tutorials Can Be
References Called
Exercises with Variables Sign In
HTML CSS do not
Arguments JAVASCRIPT SQL They
have to be values. PYTHON JAVA
can also be PHP
variables. HOW TO [Link] C
Example
let x = 5;
let y = 6;
function multiply(a, b) {
return a * b;
}
multiply(x, y);
Common Mistakes
Confusing Parameters and Arguments
Parameters are names. Arguments are values.
Forgetting the Order
Arguments are assigned to parameters by position.
Missing Arguments
Use default values to avoid undefined.
Quiz
What happens when a function is called with fewer arguments than parameters?
Next Chapter
[Link] 7/10
1/16/26, 5:39 PM JavaScript Function Parameters
Next: Returning Values from Functions
Tutorials References Exercises Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
❮ Previous Sign in to track progress Next ❯
COLOR PICKER
--> PLUS SPACES
[Link] 8/10
1/16/26, 5:39 PM JavaScript Function Parameters
Tutorials References
GET CERTIFIED
Exercises
FOR TEACHERS
Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO [Link] C
BOOTCAMPS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
[Link] Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
AngularJS Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
[Link] 9/10
1/16/26, 5:39 PM JavaScript Function Parameters
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
Tutorials References learning.
Exercises
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
Sign In
HTML
of
CSSall content. While
JAVASCRIPTusing W3Schools,
SQL you agree
PYTHONto have read and accepted
JAVA PHPour terms of use,
HOW [Link] C
and privacy policy.
Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].
[Link] 10/10