0

I am trying to load a todo model from my todo class and I have two options. The first one is

var {todo}= require("./models/todo"); 

and second one is

var todo=require("./models/todo");

I am confused which is what.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

2 Answers2

0

The first one is a destructuring assignment. It means "take an object from "models/todo" and assign its property "todo" to my local variable "todo". If it contains no such property, you'll get undefined assigned to the variable.

Andrey Antipov
  • 370
  • 3
  • 9
-1

For example this if is your model

module.exports = {
    toLower: obj => {



    },
    streamIdea: async (idea) => {


    }
}

if you're doing this

 const model = require('mymodel');

then you have to call your functions like this,

 model.toLower()

which means you're importing everything and calling it by function name

and if you're importing like this:

const { toLower } = require('mymodel');

it means you're only importing toLower from this model now you can just call it like this

 toLower();

without need of model.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Wasif Khalil
  • 2,217
  • 9
  • 33
  • 58