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.