Skip to content

Commit 86f9b59

Browse files
committed
updated
1 parent 437e827 commit 86f9b59

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

Destructuring.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let arr = [3, 5, 8, 9, 12, 14];
2+
// No need to do this:
3+
// let a = arr[0]
4+
// let b = arr[1]
5+
// let [a, b, c, d, ...rest] = arr
6+
// console.log(a, b, c, d, rest)
7+
// let [a, , b, ...rest] = arr
8+
// console.log(a, b, rest)
9+
let { a, b } = { a: 1, b: 5 };
10+
// console.log(a, b)
11+
12+
// Spread Operator
13+
let arr1 = [3, 5, 8];
14+
let obj1 = { ...arr1 };
15+
console.log(obj1);
16+
17+
function sum(v1, v2, v3) {
18+
return v1 + v2 + v3;
19+
}
20+
21+
console.log(sum(...arr1));
22+
23+
let obj2 = {
24+
name: "Harry",
25+
company: "Company xyz",
26+
address: "XYZ",
27+
};
28+
29+
// console.log({ ...obj2, name: "John", company: "ABC" })
30+
console.log({ name: "John", company: "ABC", ...obj2 }); // This will print the obj2 object without changing any values
31+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
32+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

JavaScript Notes.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
script tag must be loaded in last, as it won't recognize the body tag, if defined earlier than it.
22
*************************************************************************
3+
==> WHAT IS JAVASCRIPT???
4+
- It is a single-threaded language. (can do one task at a time)
35

6+
- It is a non-blocking language (doesnot make other operations wait, if one operation is taking time for execution such as in setTimeout).
7+
8+
- It is a asynchronous concurrent language (can see non- blocking behaviour of JS).
9+
10+
- JS runtime can do only one operation at a time. (Browser, APIs are not a part of runtime hence we are able to perform multiple operations with the assistance of APIs and browser support)
11+
12+
- It has a call stack, event loop, and a callback queue+ other APIs.
13+
14+
- V8 is JS runtime which has call stack and a heap.
15+
16+
- The heap is used for memory allocation and stack holds the execution context.
17+
18+
- DOM, setTimeout XML Http Request doesnot exist in V8 source code.
19+
20+
- Task Queue --> As JS can execute one task at a time, the rest tasks are queued waiting to be executed.
21+
22+
- Call Stack --> the order in which operations are executed. All the operations to be executed are stored in a stack, and follows the stack behaviour for e.g.
23+
24+
greeting=()=>{
25+
hello=()=>{
26+
27+
}
28+
}
29+
stack order--> greeting(), hello();
30+
hello() will be executed first and leaves the stack, then greeting() will starts to execute.
31+
32+
- Event Loop -->
33+
JS has a runtime model based on event loops, which is responsible for the execution of code, collecting and processing events, and executing sub-tasks.
34+
pushes the operations from task queue to the call stack.
35+
36+
setTimeout (fun, 0) --> when set timeout is run with 0 parameter, it means that the task should be delayed until other tasks are completed.
37+
38+
*************************************************************************
439
Javascript is a dynamically types language. We do not have to tell the datatype of a variable.
540
for e.g. if we are working in python while initializing the variable we have to define its datatype. Whereas, in JS there is no such thing.
641

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body>
99

1010
</body>
11-
<script src="ErrorHandling.js">
11+
<script src="RegularExpressions.js">
1212

1313
</script>
1414
</html>

0 commit comments

Comments
 (0)