Require VS import


import{----} from "file path.js"

to import we need to create a package.son in the same directory as that of the file 



and in the package object we need to write

"type": "module"

to import a file we should export it from another file

export

export const sum=(a,b)=> a+b;
export const mul=(a,b)=> a*b;
export const pi=3.14;
export const g=9.8;

import


import{sum,mul} from "./export.js";
console.log(sum(3,4));
console.log(mul(3,44));



 require VS import

with Require we need to select the complete file info but with Import we can select the required info

Loading is synchronous for require

and asynchronous for import

we can only use either import or require for a project we cannot use borh.

Comments

Popular posts from this blog

DATABASE RELATIONSHIPS

ROUTING (GET /) home route

Query Strings