Skip to content

Commit 58709be

Browse files
authored
Add files via upload
1 parent 2157209 commit 58709be

File tree

8 files changed

+328
-0
lines changed

8 files changed

+328
-0
lines changed

041-Shallow-copy-Object.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
author : Jaydatt Patel
3+
4+
Shallow copy : In Shallow copy, It copy just first level of key and value. If value is any object or array then it will just copy the address of that value.
5+
6+
Note : You can not copy function in Shallow or Deep Copy. Its Possible Library function.
7+
8+
*/
9+
10+
11+
var user1 = {
12+
name: 'Amit',
13+
marks:{
14+
maths:20,
15+
}
16+
};
17+
18+
console.log('----Shallow Copy using spread----');
19+
var user2 = { ...user1 };
20+
console.log('\nuser2 :',user2);
21+
console.log('\nuser1 :',user1);
22+
23+
user2.name = 'Harry'; //this will apply only to user2
24+
user2.marks.maths = 10; // this will apply to user1 and user2
25+
console.log('\nuser2 :',user2);
26+
console.log('\nuser1 :',user1);
27+
28+
console.log('\n----Shallow Copy using Object.assign----');
29+
var user2 = Object.assign({}, user1);
30+
console.log('\nuser2 :',user2);
31+
console.log('\nuser1 :',user1);
32+
33+
user2.name = 'Harry'; //this will apply only to user2
34+
user2.marks.maths = 10; // this will apply to user1 and user2
35+
console.log('\nuser2 :',user2);
36+
console.log('\nuser1 :',user1);
37+

042-Deep-Copy-Object.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
author : Jaydatt Patel
3+
4+
Deep copy : In Deep copy, It will copy all key and values from object also array, number,string, object. But not functio.
5+
6+
Note : You can not copy function in Shallow or Deep Copy. Its Possible Library function.
7+
8+
*/
9+
var user1 = {
10+
name: 'Amit',
11+
marks:{
12+
maths:20,
13+
}
14+
};
15+
16+
console.log('----Deep Copy using JSON----');
17+
// conver object to JSON string and then JSON String To Object
18+
var user2 = JSON.parse(JSON.stringify(user1));
19+
console.log('\nuser2 :',user2);
20+
console.log('\nuser1 :',user1);
21+
22+
user2.name = 'Harry';
23+
user2.marks.maths = 10;
24+
console.log('\nuser2 :',user2);
25+
console.log('\nuser1 :',user1);

043-JSON.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
author : Jaydatt Patel
3+
4+
JavaScript Object Notation (JSON):
5+
6+
The modern web consists of millions and millions of web pages, connected services and databases.
7+
8+
For example, if the stringified JSON data was converted to an object that had the following structure:
9+
10+
const ObjectOfJSON = {
11+
USD: 'str',
12+
GBP: [],
13+
EUR: {}
14+
}
15+
16+
const ArrayOfJSON = [
17+
{ USD: 'str' },
18+
{ GBP: [] },
19+
{ EUR: {} }
20+
]
21+
22+
23+
JSON is just a string - but there are rules that it must follow :
24+
- JSON is a string, but it must be a properly-formatted string. In other words, it must adhere to some rules.
25+
- If a JSON string is not properly formatted, JavaScript would not be able to parse it into a JavaScript object.
26+
- JSON can work with some primitives and some complex data types, as described below.
27+
- Only a subset of values in JavaScript can be properly stringified to JSON and parsed from a JavaScript object into a JSON string.
28+
29+
These values include:
30+
31+
- primitive values: strings, numbers, bolleans, null
32+
- complex values: objects and arrays (no functions!)
33+
- Objects have double-quoted strings for all keys
34+
- Properties are comma-delimited both in JSON objects and in JSON arrays, just like in regular JavaScript code
35+
36+
String properties must be surrounded in double quotes. For example:
37+
"fruits", "vegetables"
38+
39+
Number properties are represented using the regular JavaScript number syntax; e.g
40+
5, 10, 1.2
41+
42+
Boolean properties are represented using the regular JavaScript boolean syntax, that is:
43+
true, false
44+
45+
Null as a property is the same as in regular JavaScript; it's just a null
46+
47+
*/
48+
49+
const obj = {
50+
name : 'Rahul',
51+
sub : ['eng','math'],
52+
info : {
53+
email: 'abc@xyz.com',
54+
contact: '+12345'
55+
}
56+
}
57+
58+
// JSON.stringify(obj) to make object to JSON string format
59+
const Jstr = JSON.stringify(obj);
60+
console.log('JSON String format : ',Jstr);
61+
62+
//JSON.parse(Jstr) to conert JSON string into object.
63+
const obj2 = JSON.parse(Jstr);
64+
console.log('Object : ', obj2);
65+

044-Error_Handle.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
/*
3+
* Author : Jaydatt Patel
4+
error handling:
5+
try{
6+
7+
} catch(){
8+
9+
}catch(){
10+
11+
}......{
12+
13+
}finally{
14+
15+
}
16+
17+
Here are some of the most common errors in JavaScript:
18+
ReferenceError
19+
SyntaxError : syntax error can not work with try and catch block
20+
TypeError
21+
RangeError
22+
23+
There are some other errors in JavaScript. These other errors include:
24+
AggregateError
25+
Error
26+
InternalError
27+
URIError
28+
*/
29+
30+
console.log("\n----------Reference Error");
31+
try {
32+
console.log(username);
33+
} catch(error) {
34+
console.log("ReferenceError: username is not defined");
35+
}
36+
37+
try {
38+
xyzFunction();
39+
} catch(error) {
40+
console.log("ReferenceError: xyzFunction() is not defined");
41+
}
42+
43+
44+
console.log("\n----------Syntax Error");
45+
console.log("Syntax error must ne solved before run program",
46+
"This problem can not be resolved using try and catch block");
47+
48+
49+
console.log("\n----------Type Error");
50+
try {
51+
"hello".get();
52+
} catch(error) {
53+
console.log("TypeError:\"hello\".get is not a function");
54+
}
55+
56+
console.log("\n----------Range Error");
57+
try {
58+
console.log((10).toString(2)); // '1010'
59+
console.log((10).toString(50)); // error, rnage for tostring(2 to 36)
60+
} catch(error) {
61+
console.log("RangeError: toString() radix argument must be between 2 and 36 at Number.toString ");
62+
}
63+

045-Error_Handle.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
error handle Sample program
4+
*/
5+
6+
console.log("-----------Program-1-------------");
7+
function addTwoNums(a,b) {
8+
try {
9+
if(typeof(a) != 'number') {
10+
throw new ReferenceError('the first argument is not a number')
11+
} else if (typeof(b) != 'number') {
12+
throw new ReferenceError('the second argument is not a number')
13+
} else {
14+
console.log(a + b)
15+
}
16+
} catch(err) {
17+
console.log("Error!", err)
18+
}
19+
}
20+
addTwoNums(5, "5")
21+
console.log("It still works")
22+
23+
24+
console.log("-----------Program-2-------------");
25+
function letterFinder(word, match) {
26+
if(typeof(word) == 'string' && word.length >= 2 &&
27+
typeof(match) == 'string' && match.length == 1)
28+
{
29+
for(var i = 0; i < word.length; i++)
30+
{
31+
if(word[i] == match)
32+
console.log('Found the', match, 'at', i);
33+
else
34+
console.log('---No match found at', i);
35+
}
36+
}else{
37+
console.log("Please pass correct arguments to the function.");
38+
}
39+
}
40+
41+
letterFinder(5,2);
42+
letterFinder("cat", "c");

046-Map-and-Set-data_Structure.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
Objects : var = { Prop : val,...}
4+
5+
Map : var = new Map()
6+
Data can be stored with realting hash value using map. Hash value can not be same.
7+
8+
Set : var = new Set(array)
9+
Other : Queues, Linked lists (singly-linked and doubly-linked), Trees, Graphs
10+
*/
11+
12+
console.log("-----------Map");
13+
let bestBoxers = new Map();
14+
bestBoxers.set(1, "The Champion");
15+
bestBoxers.set(2, "The Runner-up");
16+
bestBoxers.set(3, "The third place");
17+
bestBoxers.set(1, "xyz");
18+
19+
console.log(bestBoxers);
20+
21+
console.log("bestBoxers.get(1) : ",bestBoxers.get(1));
22+
23+
// In set there are no duplicate values.
24+
// Elements of Set can not be accessed by index.
25+
console.log("-----------Set-1");
26+
const repetitiveFruits = ['apple','pear','apple','pear','plum', 'apple'];
27+
const uniqueFruits = new Set(repetitiveFruits);
28+
console.log(uniqueFruits);
29+
30+
console.log("-----------Set-2");
31+
let set = new Set();
32+
set.add(1);
33+
set.add(2);
34+
set.add(3);
35+
set.add(4);
36+
set.add(1);
37+
set.delete(4);
38+
console.log(set);
39+
console.log("set.size:",set.size);
40+
41+
console.log("-----------Set-3");
42+
var s1 = new Set([1,2,3,4]);
43+
console.log('typeof(s1): ', typeof(s1));
44+
console.log('s1: ', s1);
45+
46+
console.log("-----------Set-4");
47+
arr1 = [1,2,4,5,7];
48+
arr2 = [3,4,6,7,9,0];
49+
function mergeArray(arr1,arr2){
50+
//Implemet your function here
51+
let arr = [...new Set([...arr1,...arr2])];
52+
return arr;
53+
}
54+
console.log(mergeArray(arr1,arr2));

100-Print_data.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Author : Jaydatt Patel
3+
consol.log(...+....+...+...) not add space among strings automatically
4+
consol.log(...,....,...,...) add space among strings automatically
5+
*/
6+
var str = "Hello";
7+
var year = 2023;
8+
var arr = ['aa','bb','cc','dd'];
9+
console.log(str,'World');
10+
console.log(str,'World',year);
11+
console.log("concate: ", str.concat('World'));
12+
console.log("arr : " + arr);
13+
console.log("(10>3) : " + (10>3));
14+
console.log("(10<3) : " + (10<3));
15+
console.log("'3' + 3 : " + '3' + 3);
16+
console.log("3 + '3' : " + 3 + '3');
17+
console.log("'3' + '3' : " + '3' + '3');
18+
console.log("3 + 3 : " + 3 + 3);
19+
console.log("(3 + 3) : " + (3 + 3));
20+
console.log(3 + 3);
21+
22+
23+
24+
25+
26+
27+

101-Chrome_consol.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Author : Jaydatt Patel
3+
* Run this program in Chrome Browser consol
4+
*/
5+
6+
7+
8+
console.log("Hello, World");
9+
console.log("%cHello, World", "color: blue; font-size: 40px");
10+
console.log("Hello " + "there, " + "World");//Not space add automatically
11+
console.log("Hello","there,","World");//space add automatically
12+
13+
alert("Alert Massage Small Popup Window...");//to popup window for alert
14+
confirm("Do you want to continue ?");// conformation window to get true and false
15+
prompt("Enter Value:"); //get input from user

0 commit comments

Comments
 (0)