Node JS Coding Practice 1

 

Import and Export an Array using ES6 Module Syntax

Create two files

exportArray.mjs
,
importArray.mjs
parallel to
README.md
file.

Write an array with the values as

"countries", 190, "continents", 7, false, 6.2
in the
exportArray.mjs
file and export it using the default export syntax.

Import the array in the

importArray.mjs
file.

Use the ES6 module syntax

Import and Export a Boolean

Import and Export a Boolean using Common JS Module Syntax

Create two files

exportBoolean.js
,
importBoolean.js
parallel to
README.md
file.

Write a boolean with the value as

true
in the
exportBoolean.js
file and export it using the default export syntax.

Import the boolean value in the

importBoolean.js
file.

Use Common JS module syntax

Import and Export a Function

Import and Export a Function using Common JS Module Syntax

Create two files

exportFunction.js
,
importFunction.js
parallel to
README.md
file.

Write a JS function that returns the

This is a Function
text, in the file
exportFunction.js
and export it using the default export syntax.

Import the function in the

importFunction.js
file.

Use Common JS module syntax

.

Import and Export a Function with Parameter using Common JS Module Syntax

Create two files

exportFunctionWithParameter.js

,

importFunctionWithParameter.js

parallel to

README.md

file.

Write a JS function that accepts a number and returns its square, in the file

exportFunctionWithParameter.js

and export it using the default export syntax.

Import the function in the

importFunctionWithParameter.js

file.

Use Common JS module syntax

.

Import and Export Multiple Values using ES6 Module Syntax

Create two files

exportMultipleValues.mjs
,
importMultipleValues.mjs
parallel to
README.md
file.

Write an array, object and a function that in the file

exportMultipleValues.mjs
and export them using the named export syntax.

Import the values in the

importMultipleValues.mjs
file.

Use ES6 module syntax

.

The variable names and values are given in the below table,

VariableTypeDescription/Value
myArrayArray["camel", 265, true, "5.6"]
bulbObject{watts: 10, type: "LED"}
multiplyByFourFunctionShould accept a number and return a number multiplied by four

Import and Export a Number using ES6 Module Syntax

Create two files

exportNumber.mjs
,
importNumber.mjs
parallel to
README.md
file.

Write a JS program to export the number

25
from the file
exportNumber.mjs
and export it using the default export syntax.

Import the number in the

importNumber.mjs
file.

Use ES6 module syntax

Import and Export a Number using ES6 Module Syntax

Create two files

exportNumber.mjs
,
importNumber.mjs
parallel to
README.md
file.

Write a JS program to export the number

25
from the file
exportNumber.mjs
and export it using the default export syntax.

Import the number in the

importNumber.mjs
file.

Use ES6 module syntax

Import and Export an Object using Common JS Module Syntax

Create two files

exportObject.js
,
importObject.js
parallel to
README.md
file.

Write an object with keys as

firstName
and
lastName
and values as
John
and
Wilson
respectively in the file
exportObject.js
and export it using the default export syntax.

Import the object in the

importObject.js
file.

Use Common JS module syntax

Import and Export a String using ES6 Module Syntax

Create two files

exportString.mjs
,
importString.mjs
parallel to
README.md
file.

Write a string

Be Happy and Safe
in the file
exportString.mjs
and export it using the default export syntax.

Import the string in the

importString.mjs
file.

Use ES6 module syntax

.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form