Skip to content

ES6 Required Parameters

aidanlincoln profile image AidanLincoln github logo ・1 min read  

Have you ever made a function that should require parameters to be passed in? Probably. In ES6 you can use default parameters to achieve this goal.

First you can make a function that returns an error message. This error function can be used as a default parameter in any function you make.
Now if you call the function you made without providing the necessary parameters, an error will be thrown.


function error() {
throw new Error("Missing parameter");
function test(parameter = error()) {
return parameter;

test() // "Missing parameter"
test("hi") // "hi"

twitter logo DISCUSS (1)
markdown guide

First off, in the lines before and after the code, add 3 backticks, then add "js" to the right of the first 3 bacticks, should look something like this, if done correctly:

const myFunc = Object.freeze(function test() [
    let b = 100*2
    return b
Classic DEV Post from Jul 27 '19

If You Don't Know, Now You Know - GitHub Is Restricting Access For Users From Iran And A Few Other Embargoed Countries

Please help our cause against modern-day discrimination

AidanLincoln profile image