JS-101-Fundamentals
  • JavaScript Library
  • 1-JavaScript Fundamentals
    • 0-Getting Started
      • Welcome
    • 1-JS-Fundamentals
      • 1-Grammar and Types
        • Comments
        • Declarations
        • Scope
        • Hoisting
        • Types
        • Literals
      • 2-Control Flow and Error Handling
        • if
        • if else
        • switch
        • try catch
        • throw
      • 3-Loops
        • For Loops
        • For In Loops
        • For Of Loops
        • Do While
        • While Loops
      • 4-Functions
        • Declarations
        • Expressions
        • Calling Functions
        • Scope
        • Parameters
        • Arguments
        • Closures
        • Closures Challenge
        • Arrow Functions
        • Predefined
      • 5-Expressions and Operators
        • Assignment
        • Comparison
        • Ternary
        • Typeof
        • Left Hand Side
        • Spread
      • 6 Numbers and Dates
        • Numbers
          • Numbers Enhanced
        • Math
        • Dates
      • 7 String Methods
        • String Literals
        • Methods
      • 8 Regular Expressions
        • Basic Intro
      • 9 Arrays
        • Array Review
        • Populating/Referring
        • Length
        • Iterating
        • Methods
      • 10 Objects
        • About Objects
        • Properties
        • Enumeration
        • Initializers
        • Constructor Functions
        • this
        • create
        • Methods
      • 11 ES6 Intro
        • ES6 Intro
        • let
        • const
Powered by GitBook
On this page
  • File Location
  • Sample Code
  • Arguments
  • Key Points
  1. 1-JavaScript Fundamentals
  2. 1-JS-Fundamentals
  3. 4-Functions

Parameters

A parameter is a variable in a method definition. To say it another way, a parameter is the variable in the declaration of the function, and it is found inside of the parenthesis.

File Location

We will be working in the following file:

    javascript-library
        └── 0-PreWork
        └── 1-Fundamentals
            └── 4-Functions
                05-parameters.js <----You will be working in this file.

Sample Code

In the function below, we see two parameters: name & type.

function petNameAndBreed(name, type){
    var petDetails = name + ", " + type;
    console.log(petDetails);
    return petDetails;
}

Arguments

We'll talk in the next module about arguments, but the following function calls show how the parameters work like variables. We put a different value in each time we call it:

petNameAndBreed("Johnny", "Tortoise Shell Cat");
petNameAndBreed("Sansa", "Bulldog");

Key Points

We'll get a lot more practice with parameters in the future. The key takeaways are these points:

  1. Parameters are like variables.

  2. Declared in the parenthesis of a function.

  3. The arguments are the values that get assigned to the parameters when the function is called.

PreviousScopeNextArguments

Last updated 7 years ago