You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// - The reverse() method in JavaScript is used to reverse the order of elements in an array.
5
+
6
+
// Why
7
+
// - The reverse() method is useful when you need to manipulate or process an array by reversing its order.
8
+
// - It is commonly used in various programming scenarios, such as sorting data in descending order, reversing a sequence of elements, or creating user-friendly interfaces.
9
+
10
+
// How
11
+
// - The reverse() method modifies the original array in-place and does not create a new array.
12
+
// - It reverses the order of elements in the array by swapping the first element with the last element, the second element with the second-to-last element, and so on.
// - The reverse() method modifies the original array in-place. If you need to preserve the original order of elements, you should create a copy of the array before calling the reverse() method.
44
+
// - The reverse() method does not return a new array. Instead, it modifies the existing array.
// - "Use strict" is a directive in JavaScript that activates strict mode, a stricter set of rules for interpreting and executing JavaScript code.
7
5
@@ -10,3 +8,24 @@
10
8
11
9
// How
12
10
// - To activate strict mode, you include the string literal "use strict"; at the beginning of a script or a function. This directive tells the JavaScript engine to interpret the code that follows it in strict mode.
11
+
12
+
// Syntax
13
+
"use strict";
14
+
15
+
// Example
16
+
// Strict mode example
17
+
functionsum(a,b){
18
+
returna+b;
19
+
}
20
+
21
+
console.log(sum(1,"2"));// This will throw a TypeError in strict mode
22
+
23
+
// Note
24
+
// - The use strict directive should be placed at the beginning of a script or function to enable strict mode for that scope.
25
+
// - Strict mode can help catch common coding errors and enforce best practices, making your code more reliable and secure.
26
+
27
+
// When
28
+
// - Use the use strict directive to enable strict mode in your JavaScript code.
29
+
// - Use strict mode to catch common coding errors and enforce best practices.
30
+
// - Use strict mode when working on large projects or collaborating with others to ensure consistent code quality.
31
+
// - Use strict mode when you want to write modern JavaScript code that leverages new features and best practices
// - `var` keyword has been deprecated so it's not recommended to use.
5
-
// - It can be initialized later.
6
-
// - It can be redeclare.
7
-
// - It can be reassigned.
8
-
// - It has global scope.
1
+
// `var` Keyword (Not Recommended)
9
2
10
3
// Syntax
11
4
// var variableName = value;
@@ -20,4 +13,11 @@ var variable = "value";
20
13
21
14
// Reassigned
22
15
varvariable="value1";
23
-
variable="value2";
16
+
variable="value2";
17
+
18
+
// Note
19
+
// - It can be initialized later.
20
+
// - It can be redeclare.
21
+
// - It can be reassigned.
22
+
// - It has global scope.
23
+
// - The var keyword is not recommended for modern JavaScript development. It has been deprecated and replaced with let and const. Using var can lead to unexpected behavior and bugs in your code.
// - The const keyword in JavaScript is used to declare a read-only variable.
5
5
6
-
// When
7
-
// - Always declare a variable with const when you know that the value should not be changed.
8
-
// Use const when you declare:
9
-
// A new Array
10
-
// A new Object
11
-
// A new Function
12
-
// A new RegExp
6
+
// Why
7
+
//- The const keyword is used to declare variables in JavaScript to store and manipulate data. It provides immutability and helps prevent accidental modifications to variables.
8
+
//- The const keyword is recommended for modern JavaScript development as it enforces read-only variables and helps prevent bugs.
13
9
14
-
// Note
15
-
// - It can only initialized when it's declared.
16
-
// - It can't be reassigned.
17
-
// - It can't be redeclare.
18
-
// - It can be redeclare but in different scope.
10
+
// How
11
+
// - When you declare a variable using the const keyword, JavaScript reserves memory space to store the variable's value. You can then assign a value to the variable and use it in your program.
12
+
// - The const keyword ensures that the variable's value cannot be modified once it is assigned. If you try to reassign a value to a const variable, JavaScript will throw an error.
19
13
20
14
// Syntax
21
15
// const constantName = value;
@@ -40,13 +34,25 @@ function myFunction(parameter) {
40
34
41
35
// Constant Objects and Arrays
42
36
// - The keyword const is a little misleading.
43
-
// - It does not define a constant value. It defines a constant reference to a value.
37
+
// - It does not define a constant value. It defines a constant reference to a value. Because of this...
44
38
45
-
// Because of this you can NOT:
39
+
// Can't:
46
40
// - Reassign a constant value
47
41
// - Reassign a constant array
48
42
// - Reassign a constant object
49
43
50
-
// But you CAN:
44
+
// Can:
51
45
// - Change the elements of constant array
52
-
// - Change the properties of constant object
46
+
// - Change the properties of constant object
47
+
48
+
// Note
49
+
// - It can initialized & declared at same time.
50
+
// - It can't be reassigned.
51
+
// - It can't be redeclare.
52
+
// - The const keyword is not hoisted, meaning it cannot be accessed before it is declared in the code.
53
+
// - The const keyword allows you to declare variables with the same name within different scopes, as long as they are in different blocks.
54
+
// - The const keyword is block-scoped, meaning that the variable's value can only be accessed within the block where it is declared.
55
+
56
+
// When
57
+
// - Always declare a variable with const when you know that the value should not be changed.
58
+
// - Use const when you declare a new array, object or function
// - Data types in JavaScript are the different types of values that can be stored and manipulated in a program.
5
+
// - They define the kind of data that a variable can hold and the operations that can be performed on that data.
6
+
7
+
// Why
8
+
// - Data types help ensure that your program behaves correctly and handles different types of data appropriately.
9
+
// - They provide a foundation for writing robust and maintainable code.
10
+
11
+
// How
12
+
// - JavaScript has a set of built-in data types that define the kind of values that can be stored and manipulated in a program. These data types include:
13
+
// - Number: Represents numeric values, including integers and floating-point numbers.
14
+
// - String: Represents textual data, enclosed in quotes.
15
+
// - Boolean: Represents logical values, which can be either true or false.
16
+
// - Object: Represents complex data structures, such as arrays, functions, and custom objects.
17
+
// - Undefined: Represents a variable that has not been assigned a value.
18
+
// - Null: Represents a variable that has been explicitly assigned a value of null.
19
+
20
+
// Undefined
21
+
// - You can assign literally a value as a `undefined`
22
+
letundefined1=undefined;
23
+
// - Declared variable which doesn't assigned any value yet also has undefined as a value.
24
+
letundefined2;
25
+
26
+
// Null
27
+
// - Null is standalone value. To understand this let say you are creating weather application which give you the temperature of selected city. For any reason server unable to send you the temperature that means there is no temperature value. At that case weather app shouldn't show `0` on screen. Because 0 also refer as temperature value. At that time we use null to show there is actually no temperature and server are unable to fetch data of temperature.
28
+
// - WHEN CHECK THE TYPEOF NULL IT WILL SHOW IT IS AN OBJECT.
0 commit comments