Skip to content

Commit 0ede235

Browse files
committed
2nd
1 parent bc1de5b commit 0ede235

File tree

9 files changed

+367
-2
lines changed

9 files changed

+367
-2
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

fakerr.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
2+
3+
function empTemplate(firstName, email){
4+
this.firstName = firstName;
5+
this.email = email;
6+
return this;
7+
}
8+
9+
function numEmp(numberOfEmployee){
10+
console.log(numberOfEmployee);
11+
console.log(typeof numberOfEmployee);
12+
if(typeof numberOfEmployee == "string"){
13+
console.log("Input Number not a string");
14+
// return;
15+
}
16+
if(numberOfEmployee<1){
17+
console.log("Number of employee is less than 1")
18+
}
19+
const arr = [];
20+
for(let i=0;i<numberOfEmployee;i++){
21+
console.log(typeof i);
22+
console.log(i);
23+
//const emp = new empTemplate(faker.name.fullName(),faker.internet.email());
24+
arr.push(new empTemplate(faker.name.fullName(),faker.internet.email()));
25+
26+
}
27+
console.log(arr);
28+
}
29+
//whenver creating fucntion think of all the values that goes into it
30+
//Write the cases for it while writing the function itselfs
31+
//ask this question while creating a function
32+
//Input to function
33+
//Return type
34+
numEmp("abc");
35+
36+
37+
//What are JS array MDN
38+
//Modules
39+
//Callback is the most import thing use it understand it properly
40+
//Don't share the code while they are struggling

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<title>Introduction to JavaScript</title>
8-
<script src="./src/function.js"></script>
8+
<script src="./src/Array and Array Functions.js"></script>
99
</head>
1010
<body>
1111
<h2>JavaScript Tutorial</h2>

src/01-object.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//Objects hold data
2+
//Gives structure to the data requirement of the application
3+
const headerInformation = {
4+
5+
};
6+
7+
//what exactly is an object
8+
const obj1 = {
9+
// key1:value1
10+
};
11+
//Collection of key value pairs
12+
//value can be anything.
13+
//Key either has to be some string
14+
15+
const emp = {
16+
"firstName": "raj",
17+
"lastName":"pandey"
18+
};
19+
20+
//How to create multiple object with same structure
21+
//In Js we perfrom something with function and return value
22+
//In js function always returns something
23+
//By default function returns undefined
24+
//function can return anything
25+
function createEmployee(firstName, lastName){
26+
console.log("Creating the employee object");
27+
const template = {
28+
firstName:firstName,
29+
lastName:lastName,
30+
company: "Contentstack",
31+
isIntern: true
32+
};
33+
return template
34+
}
35+
const emp1 = createEmployee("thor","odinson");
36+
console.log(emp1);
37+
38+
const emp2 = createEmployee("tony","stark");
39+
console.log(emp2);
40+
41+
emp1.firstName = "jane";
42+
console.log(emp1);
43+
console.log(emp2);

src/02-createObject.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//using function constructor
2+
function Employee(firstName, lastName){
3+
this.firstName = firstName;
4+
this.lastName = lastName;
5+
this.company = "Contentstack";
6+
this.isIntern = true;
7+
return this;
8+
}
9+
10+
const emp1 =new Employee("raj","p");
11+
//when something is declared as modeul it becomes self contained piece of code
12+
//Variables cannot be accessed

src/Array and Array Functions.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,55 @@ function Employee(id,name,profileImage,introduction,profileLink){
1111
return this;
1212
}
1313

14+
//Arguement -- Array containing the list of employee objects
15+
//Return type -- employee Object whose id is present else error message and return undefined
16+
function findEmployeeById(empObjArr,empid){
17+
return empObjArr.find((empObj)=>empObj.id==empid );
18+
}
19+
20+
//Arguement -- Object containing property on which we have to find the employee
21+
//Return type - Employee object that matches the search query
22+
function findEmployeeAllKeys(empObjArr,queryObj){
23+
let foundEmployee = [];
24+
const queryKeys = Object.keys(queryObj);
25+
let employeeFound = false;
26+
console.log(queryObj[queryKeys[0]]);
27+
for(let i = 0;i<queryKeys.length;i++){
28+
employeeFound = false;
29+
for(let j = 0;j<empObjArr.length;j++){
30+
if(empObjArr[j][queryKeys[i]]===queryObj[queryKeys[i]]){
31+
foundEmployee = empObjArr[j];
32+
}
33+
}
34+
}
35+
console.log(employeeFound);
36+
}
37+
38+
//Arguement -- Object containing property on which we have to find the employee
39+
//Return type - Employee object that matches the search query
40+
function findEmployee(empObjArr,queryObj){
41+
const queryKey = Object.keys(queryObj)[0];
42+
// console.log()
43+
const empObj = [];
44+
empObjArr.find(function(element){
45+
if(element[queryKey]===queryObj[queryKey]){
46+
empObj.push(element);
47+
}
48+
});
49+
if(empObj.length!==0){
50+
return empObj;
51+
}
52+
else{
53+
console.log("There's No Match to your query");
54+
return;
55+
}
56+
57+
}
58+
59+
//Arguement -- id, update object
60+
function updateEmployeeById(empObjArr,id,updateObject){
61+
62+
}
1463
//Data Source
1564
const employees = [
1665
{
@@ -130,4 +179,7 @@ function createEmployee(){
130179
});
131180
}
132181
createEmployee();
133-
console.log(EmployeeArr);
182+
//findEmployeeAllKeys(EmployeeArr,{'id':"1",'name':"Vibhuti Bajaj"});
183+
console.log(findEmployee(EmployeeArr,{'id':"9"}));
184+
// console.log(EmployeeArr);
185+
// console.log(findEmployeeById(EmployeeArr,22));

src/app.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//First the index.html file is loaded and then the files which are included in the header are loaded
2+
// ./ means on the same server, It represents the place where server is actually running
3+
//Browser will request index file first. The source file will be request next
4+
//Once the script file is loaded we can access variable in browser itself
5+
console.log("Hello World");
6+
7+
//Agenda of todays session
8+
//Variables
9+
//Objects
10+
//Functions
11+
//Combination of Objects and function
12+
13+
// Variable
14+
// Primitives -- booolean, null, number, string, undefined
15+
// Objects -- arrays, objects, dates, functions, wrappers(string, boolean, numbers)
16+
17+
// (ES5) var, (ES6)let, const
18+
// typeof -- is operator // to get the datatype of variable
19+
var num1 = 100;
20+
var num2 = 200;
21+
var num3 = num1; //Here the value is getting copied
22+
num1 = 150;
23+
24+
//Primitive type will hold its value in the memory location and for every new variable new memory location would be created.
25+
26+
var firstName = "Raj"; //Strings can either be object or primitives
27+
28+
var b1 = true;
29+
30+
//Undefined implies there is no value stored in the variable
31+
//When something new is created undefined is assigned to it. ??Careful with it
32+
var lastName;
33+
34+
35+
//Objects
36+
//Arrays
37+
38+
var emp1 = {
39+
firstName:"Raj",
40+
lastName:"P."
41+
};
42+
var emp2 = emp1; //This is the place where emp2 referenced to emp1 memory block.
43+
emp2.lastName = "P."
44+
45+
//Objects are "Reference"
46+
//Everything in JavaScript in an Object, Almost Everything
47+
48+
//Array
49+
console.log("value in error ",l1); //We get the value as undefined and not the error
50+
//This is hoisting
51+
//Allows using the name of variable before it is declared and initialized
52+
var num = [10,20,30,40];
53+
var num2 = num;
54+
55+
// function funtion_name(function parameter/arguements){
56+
//business logic
57+
//}
58+
59+
//JS is scripting language
60+
//It work line by line
61+
62+
let l1 = [10,20,30,40]; //It means for l1 the value can change.
63+
const l11 = [20,20]; //It means for l11 value cannot change. constanst
64+
//const -- > value cannot be reassgined
65+
//let --> value can be reassigned
66+
//both const and let prevent hoisting
67+
//JS is loosely typed
68+
//Careful when assigning value to variables.
69+
70+
// => fat arrow notation
71+
//Assigning a function to a variable name
72+
//function are also objects and can be used as variable
73+
// const printNameES6 = () =>{§
74+
//
75+
//}
76+
//Get comfortable with basics

src/arrays.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//no concept of pointer in javascript
2+
const arr = [];
3+
function EmployeeObject(firstName, lastName, emailId){
4+
this.firstName = firstName;
5+
this.lastName = lastName;
6+
this.emailId = emailId;
7+
}
8+
9+
function copyEmployeeObject(empObject){
10+
const newObj = new Object(empObj);
11+
console.log(newObj);
12+
console.log(typeof(newObj));
13+
arr.push(newObj);
14+
return this;
15+
}
16+
17+
const empObj = new EmployeeObject('thor','odinson','thor@gmail.com');
18+
arr.push(empObj);
19+
copyEmployeeObject(empObj);
20+
console.log("thor");
21+
console.log(arr);
22+
empObj.firstName = "jane";
23+
console.log(arr);

0 commit comments

Comments
 (0)