How to get return data from function in another js file on javascript

Viewed 38

How can i retrieve a return data in another file js?

this is my user.js looks like

export default function getUser() {
    const data = localStorage.getItem("user-account")
    //console.log(data.user.ID)
    const user = {
        ID: data.user.ID,
        Name: data.user.Name, 
    }
  return user;
}

and i want to import them and get the return user in another file js, because i want to use this file as global function any solution?

1 Answers

Try importing it into another file and logging the result.

import getUser from './user'

console.log(getUser())

Take note that you need a script type of 'module' for this to work

Related