Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
See the solution for the what properties will be used in the Player Class.
Default Values
Note: This explanation will also be repeated later in the course.
Default values are a way to initialize parameters with a specific value, even if no value or undefined is passed.
If an argument is passed for that parameter, the parameter will be initialized with the passed value.
If an argument is not passed, the parameter will be initialized with the default value.
In the following example, the company
parameter has a default value of "Treehouse". If no third argument is sent when the function is called, the parameter company will still be available in the function, with a value of "Treehouse".
const name = 'Ashley';
const job = 'teacher';
printEmployee(name, job);
printEmployee(name, job, company = 'Treehouse') {
//function code here
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up