0% found this document useful (0 votes)
34 views1 page

Week 2 cn5006

The document discusses JavaScript functions and modules in Node.js. It defines a function called EmployeeInfo that takes name and salary parameters and logs a welcome message. It also covers arrow functions like defining a function called EmpSkills. It demonstrates creating local modules in Node.js like StudentInfo.js that exports functions and variables. These modules are imported into index.js using the require keyword. The code defines objects using the exported functions and runs successfully.

Uploaded by

sirjana limbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Week 2 cn5006

The document discusses JavaScript functions and modules in Node.js. It defines a function called EmployeeInfo that takes name and salary parameters and logs a welcome message. It also covers arrow functions like defining a function called EmpSkills. It demonstrates creating local modules in Node.js like StudentInfo.js that exports functions and variables. These modules are imported into index.js using the require keyword. The code defines objects using the exported functions and runs successfully.

Uploaded by

sirjana limbu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Week 2 cn5006

At first we write a code in java script (index.js) to define a function i.e. Employeeinfo that takes two
parameter (name and salary). Then we write console.log("Wellcome " + name+ "Your monthly Salary is
"+ Salary) where console.log will help to display a message or variable value in the terminal window and
we use quotes “” to display the message. We use paremeters of the function which is defined in
parentheses() and use “+” in console.log to concatenate message with the value of parameters passed in
this function which in our case is name and salary.

After that we learn about arrow function const variablename= () =>{} and we use this function as const
EmpSkills= (skills)=> { console.log("Expert in "+ skills) } and we call fuction as EmpSkill(“java”).

Then we create local module in NodeJS and name the new file as Studentinfo.js and write code like
const getCampusName = () => { return ("UEL Campus ") } and export functions & variable outside the
module by exports.Location=getCampusName and also we learn to export function with parameter by
exports.Studentgrade=(marks)=> { if (marks>50 && marks <70) return ("B grade") else return ("A
grade)") }.

Then we also create another module Person.js where we learn to export just one thing by using code
module.exports . Afte that we use the functions and object defined in these two files i.e. (StudentInfo.JS,
Person.JS) in index.js and we use “require” keyword to import a module in nodejs like const person =
require('./Person') where name is prefixed with ./, as it’s a local file. we also create new person
person1= new person("Jim","USA",myemail@gmail.com) and after writing all codes as shown in lab we
run the program and got positive results.

You might also like