Skip to content

Commit c055701

Browse files
feat: add condition statement
1 parent 84c6010 commit c055701

File tree

80 files changed

+294
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+294
-134
lines changed

08_string/string_vs_string_object.md

-11
This file was deleted.

12_object/who_is_object.md

+25

13_function/8ArrowFunction.js

-19
This file was deleted.
File renamed without changes.

13_function/arrow_function.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Arrow Function
2+
3+
// SYNTAX
4+
// const variableName = () => {
5+
// code...
6+
// return
7+
// }
8+
9+
// Simple arrow function
10+
const arrowFunction = () => {
11+
return console.log("Hello, World!");
12+
};
13+
14+
// Implicit Return
15+
16+
// Note
17+
// - If you use {} for function. You need to write the `return` keyword.
18+
const arrowFunction1 = () => {
19+
return console.log("Hello, World!");
20+
};
21+
22+
// - If you are not using the {}. You don't need to write the `return` keyword.
23+
const arrowFunction2 = () => console.log("Hello, World!");
24+
25+
// - If you are using object with arrow function without {}. You need to use ().
26+
const arrowFunction3 = () => ({ key1: "value1" });
27+
28+
// - If you are passing only one parameter. You can remove () around the parameter.
29+
// const myArrowFunction1 = parameter => console.log(parameter);
30+
31+
// () => {}
32+
// () =>
33+
// () => ()
34+
// =>

13_function/iife.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Immediately Invoked Function Expressions (IIFE)
2+
3+
// REMEMBER ME -> ;
4+
5+
// Named IIFE Function
6+
(function myFunction(parameter) {
7+
return console.log(parameter);
8+
})("I'm IIFE Function");
9+
10+
// Arrow IIFE Function
11+
((parameter) => {
12+
console.log(parameter);
13+
})("I'm Arrow IIFE Function");

15_this_keyword/1_this_keyword.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// `this` Keyword
2+
3+
// What
4+
// - In JavaScript, the this keyword refers to an current context.
5+
6+
// Note
7+
// - The this keyword refers to different objects depending on how it is used:
8+
// 1. Alone -> Global object
9+
// 2. In a object method -> object
10+
// 3. In a function -> Global object
11+
// 4. In a function with strict mode ("use strict") -> undefined
12+
// - In an event, this refers to the element that received the event.
13+
// - Methods like call(), apply(), and bind() can refer this to any object.
14+
15+
// 1. Alone -> Global object
16+
console.log(this);
17+
18+
// 2. In a object method -> object
19+
const object = {
20+
key1: "Value1",
21+
key2: "Value2",
22+
key3: function () {
23+
console.log(this.key1);
24+
},
25+
};
26+
console.log(object.key3());
27+
28+
// 3. In a function -> Global object
29+
function iAmFunction() {
30+
return console.log(this);
31+
}
32+
33+
console.log(iAmFunction());
34+
35+
// 4. Function inside function -> Global object
36+
function iAmOutsideFunction() {
37+
function iAmInsideFunction() {
38+
return console.log(this);
39+
}
40+
console.log(iAmInsideFunction());
41+
}
42+
console.log(iAmOutsideFunction());
43+
44+
// 5. Arrow function and this keyword
45+
// - Arrow functions have a different behavior with this. They inherit the this value from the enclosing scope where they are defined, not from how they are called.
46+
47+
// Defined in the Global Scope -> Global object
48+
const arrowFunction = () => {
49+
return console.log(this);
50+
};
51+
console.log(arrowFunction());
52+
53+
// Defined Inside a Function or Object
54+
const object1 = {
55+
key1: "value1",
56+
key2: "value2",
57+
key3: () => {
58+
console.log(this);
59+
},
60+
};
61+
62+
console.log(object1.key3());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Window VS Global Object
2+
3+
// Global Object
4+
// - The fundamental object that provides properties and functions accessible throughout your JavaScript code.
5+
// - In browsers, the global object is typically the window object, but this can vary depending on the environment (e.g., Node.js uses the global object).
6+
// - It contains built-in functions like console.log(), parseInt(), and properties like document (in browsers).
7+
8+
// Window Object
9+
// - A special object specific to browser environments that represents the browser window.
10+
// - It inherits properties and methods from the global object but also has additional properties and methods related to the browser window, such as location (for accessing the URL), alert(), and confirm().
11+
12+
// Key Differences
13+
// - Scope: The global object exists in all JavaScript environments, while the window object is specific to browsers.
14+
// - Properties: The window object has additional properties and methods related to the browser window functionality that the global object doesn't have.
15+
16+
// When to Use Which
17+
// - In most browser code, you can generally use window and global interchangeably since window is the de facto global object in browsers.
18+
// - However, if you're writing code that might run in different environments (e.g., Node.js), it's safer to use global to explicitly reference the global object across environments.
19+
20+
// In a browser:
21+
console.log(window === global); // Output: true (usually true in browsers)
22+
23+
// In Node.js:
24+
console.log(window === global); // Output: false (they are different objects)
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const age = 20;
2+
if (age >= 18) {
3+
console.log("You can give a vote.");
4+
} else {
5+
console.log("You can't give a vote.");
6+
}
7+
8+
const userID = true;
9+
const upiID = true;
10+
if (userID && upiID) {
11+
console.log("Welcome!");
12+
}
13+
14+
const loggedInFromGoogle = true;
15+
const loggedInFromEmail = true;
16+
if (loggedInFromEmail || loggedInFromGoogle) {
17+
console.log("Welcome!");
18+
}
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Falsy value
2+
// false
3+
// 0
4+
// -0
5+
// BigInt 0n
6+
// ""
7+
// null
8+
// undefined
9+
// NaN
10+
11+
// Truthy value
12+
// - Any value other than falsy.
13+
// "0"
14+
// "false"
15+
// " "
16+
// []
17+
// {}
18+
// function(){}
19+
20+
// For CP and Interview
21+
// false == 0 -> true
22+
// false == "" -> true
23+
// 0 == "" -> true
24+
25+
const emptyArray = [];
26+
if (emptyArray.length === 0) {
27+
console.log("Array is empty");
28+
}
29+
30+
const emptyObject = {};
31+
if (Object.keys(emptyObject).length === 0) {
32+
console.log("Objet is empty");
33+
}
File renamed without changes.

6_operators/15_spread_vs_rest_operator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// - Rest Operator:
1313
// - Captures a variable number of arguments passed to a function and handles them as an array within the function body.
1414

15-
// Spread Operator Examples:
15+
// Examples
1616

1717
// 1. Function Call with Array Elements (avoiding apply or loop)
1818
function sumNumbers(x, y) {

6_operators/7_nullish_coalescing_operator.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
let myVariable = null ?? "default value";
1010
console.log(myVariable);
11+
12+
// It will check for the value. Which ever value it will find first. It will be default value
13+
const myVariable1 = null ?? "value1" ?? "value2";
14+
console.log(myVariable1);

6_operators/9_ternary_or_conditional_operators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Ternary or Conditional Operator
22

33
// Syntax
4-
// const variableName = (condition) ? statement1 : statement2;
4+
// const variableName = (condition) ? true : false;
55

66
// Example
77
const age = 20;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

17Map/1Map.js Map/1Map.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)