This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bob1 = { | |
name : "Jack", | |
friends : [], | |
getFriends : function() { | |
console.log(this.name); | |
this.friends.forEach(function(item){ | |
console.log(this.name + " is friends with " + item); //this is undefined here | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee { | |
constructor(empNo,name,department){ | |
this.employeeNumber = empNo; | |
this.name = name; | |
this.department = department; | |
} | |
getEmployeeProfile(){ | |
return this.name + "|" + this.department + "|" + this.employeeNumber; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var employee = { | |
name : '', | |
department : '', | |
employeeNumber : '', | |
getEmployeeProfile : function() { | |
return this.name + "|" + this.department + "|" + this.employeeNumber; | |
} | |
} | |
var jack = Object.create(employee); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//function constructor | |
function Employee(empNo,name,department){ | |
this.employeeNumber = empNo | |
this.name = name; | |
this.department = department; | |
} | |
Employee.prototype.getEmployeeProfile = function(){ | |
return this.name + "|" + this.department + "|" + this.employeeNumber; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
person = { | |
firstName : "Jack", | |
lastName : "doresy", | |
getFullName : function () { | |
return this.firstName + " " + this.lastName; | |
} | |
} | |
//List down all the properties (including the function) | |
for(var prop in person){ | |
console.log(prop + "->" + person[prop]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function filterFn(arr, predicate) { | |
resultArr = []; | |
for (i = 0; i < arr.length; i++) { | |
if (predicate(arr[i])) { | |
resultArr.push(arr[i]); | |
} | |
} | |
return resultArr; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getName(){ | |
console.log(this.firstName + " " + this.lastName); | |
} | |
function Add(n1,n2){ | |
console.log(n1 + n2); | |
} | |
getName(); // undefined undefined | |
person1 = { | |
firstName : "jack", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createFunctionArray(){ | |
arr = []; | |
for(i=0;i<3;i++){ | |
let j = i; | |
arr.push (function(){ | |
console.log("i =" + i); //Always print 3 | |
console.log("j =" + j); //Prints the value of i for each iteration | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sayGreeting(greeting){ | |
var innerVar = "inner"; | |
return function() { | |
console.log(greeting + "," + innerVar); | |
} | |
} | |
var greetingFn = sayGreeting("hi"); | |
greetingFn();//prints -> hi,inner | |
// greetingFn still has access to 'innerVar' and 'greeting' passed since its part of the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{"Name":"Dix","Age":27,"Designation":"Analyst","Paygrade":"Leve1","Department":"Marketing"}, | |
{"Name":"Alphonso","Age":48,"Designation":"Director","Paygrade":"Executive","Department":"Product Management"}, | |
{"Name":"Lester","Age":36,"Designation":"Manager","Paygrade":"Level3","Department":"Services"}, | |
{"Name":"Lennard","Age":30,"Designation":"Director","Paygrade":"Level3","Department":"Legal"}, | |
{"Name":"Bryn","Age":27,"Designation":"Sr Analyst","Paygrade":"Executive","Department":"Product Management"}, | |
{"Name":"Mac","Age":40,"Designation":"Director","Paygrade":"Leve1","Department":"Training"}, | |
{"Name":"Enid","Age":34,"Designation":"Director","Paygrade":"Level3","Department":"Services"}, | |
{"Name":"Nanon","Age":44,"Designation":"Analyst","Paygrade":"Executive","Department":"Engineering"}, | |
{"Name":"Booth","Age":45,"Designation":"Director","Paygrade":"Level3","Department":"Human Resources"}, | |
{"Name":"Elsinore","Age":46,"Designation":"Manager","Paygrade":"Level2","Department":"Product Management"}] |
NewerOlder