0

consider the following:

let y = doSomething(){ //doesn't work
    console.log('sdf')
}

let y = function doSomething(){ //works
    console.log('sdf')
}



module.exports = {
    getAll(){

    }
}  

I had never seen this sort of function(inside the module.exports) is it a call or definition? It differs in that it doesn't have a keyword function, yet it's exported. What is it called? Does it have a specific name, most importantly, what are we actually doing in here? Please leave me a link to finding out more on this sort of definition if possible.

1 Answer 1

1

let y = function doSomething() {} called Function expressions

a name can be provided with a function expression. Providing a name allows the function to refer to itself, and also makes it easier to identify the function in a debugger's stack traces:

module.exports = {
  getAll(){}
}

It exports an anonymous object which has a getAll() method. It's called Method definitions

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.