Skip to content

Commit 5f5b17d

Browse files
refactor: string and function
1 parent c888b70 commit 5f5b17d

Some content is hidden

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

44 files changed

+310
-381
lines changed

08_operators/01_unary_operator/02_unary_keyword_operator/01_typeof/01_typeof.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// -> Error Handling: You can use typeof in conditional statements to check for unexpected data types and handle errors gracefully. For example, a function might expect a number as input, and you can use typeof to check before performing calculations.
99
// -> Debugging: typeof can be a valuable tool during debugging to inspect the data types of variables and identify potential issues
1010

11+
// Note:
12+
// -> typeof returns a type in string format.
13+
1114
// Syntax:
1215
// const variable = "value";
1316
// console.log(typeof variable);

8_string/1_string.js renamed to 09_string/01_string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// String
1+
// Topic: String
22

33
// Single quote
44
console.log("Single quotes");
55

66
// Double quote
77
console.log("Double quotes");
88

9-
// Backtick (Recommended)
9+
// Backtick
1010
console.log(`Backtick`);
1111

1212
// Multiline string use backtick

8_string/2_escape_sequence.js renamed to 09_string/02_escape_sequence.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Escape Sequence
1+
// Topic: Escape Sequence
22

33
// console.log("\'Single quote\'");
44
// console.log("\"Double quote\"");

8_string/3_string_concatenation.js renamed to 09_string/03_string_concatenation.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// String Concatenation
1+
// Topic: String Concatenation
22

3+
// Using + operator to concatenate strings
34
const string1 = "String";
45
const string2 = "Concatenation";
56
const result = string1 + " " + string2;

09_string/04_string_template.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Topic: String template
2+
3+
const variable = "value";
4+
console.log(`Use backtick to access ${variable} inside string`);

8_string/5_string_conversion.js renamed to 09_string/05_string_conversion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// String Conversion
1+
// Topic: String Conversion
22

33
// Number to String
4-
const number = 100;
4+
let number = 100;
55
number = String(100); // Using string constructor
66
console.log(typeof number);
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// String Index
1+
// Topic: String Index
22

33
const string = "Hello, World!";
44
console.log(string[3]);

09_string/methods/char_code_at.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Topic: charCodeAt()
2+
3+
// Q. What is charCodeAt()?
4+
// -> It returns the unicode of the character at a specified index in a string:
5+
// -> The method returns a UTF-16 code (an integer between 0 and 65535).
6+
7+
// Syntax:
8+
// string.charCodeAt(indexNumber);
9+
10+
let string = "Hello world";
11+
let variable = string.charCodeAt(3);
12+
console.log(variable);

09_string/methods/chat_at.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Topic: charAt()
2+
3+
// Q. What is charAt()?
4+
// -> The charAt() method returns the character at a specified index (position) in a string.
5+
6+
// Note:
7+
// -> If no character is found charAt() return empty string.
8+
9+
// Syntax:
10+
// string.charAt(indexNumber);
11+
12+
let string = "Hello world";
13+
let variable = string.charAt(3);
14+
// console.log(variable);
15+
16+
let string2 = "JavaScript";
17+
let variable2 = string2.charAt(100); // index out of range
18+
console.log(typeof variable2); // return empty string

09_string/methods/pad_end.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Topic: padEnd()
2+
3+
// Q. What is padEnd()?
4+
// -> It's add padding to string. As you can see in syntax there is parameter called targetLength which determine how much length string should have and there is padString parameter which take string that you want to add to original string as padding. If the original string length is less then targetLength it will take the padString and add to the original's end.
5+
6+
// Syntax:
7+
// string.padEnd(targetLength, padString);
8+
9+
let string = "Hello world";
10+
let variable = string.padEnd(20, "0");
11+
12+
console.log(variable);

0 commit comments

Comments
 (0)