-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.js
94 lines (53 loc) · 2.15 KB
/
app1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// There are two types of scopes in JS:
//Function Scope: Visibility is limited to the function.
// function myFn() {
// var x = 10;
// console.log(x); //prints 10
// }
// console.log(x); // ReferenceError: x is not defined
//Block Scope: Visibility is limited to the block of code.
// if (true) {
// let x = 10;
// console.log(x); //prints 10
// }
// console.log(x); // ReferenceError: x is not defined
// the scope of var, let and const.
// var declarations are function scoped.
// let declarations are block scoped.
// const declarations are block scoped.
//String Methods - action that can be performed on objects.
//Format - StringName.method()
//Trim Method - removes the whitespaces from both the end of string and return new one
// let msg = " Hello ";
// console.log(msg.trim());
// Note- Strings are immutable in JS that is why after the applying the methods a new strings created and return the
// expected value but the original string value remains Same
// let password = prompt("Enter your password.");
// console.log(password.trim());
//toUpperCase and toLowerCase methods
// let name = "Vaishnavi Raj";
// console.log(name.toUpperCase());
// console.log(name.toLowerCase());
//String Methods with Argument
//Argument is a some value that we pass to the method.
//Format -stringName.method(argument)
//indexOf Method - returns the first index of occurence of some value in string. Or gives -1 if not found
// let msg = "ILoveCoding";
// let name = "Microsoft";
// console.log(msg.indexOf("Love"));
// console.log(name.indexOf("soft"));
// console.log(msg.indexOf("J")); //-1(not found)
//Method Chaining - using one method after another. order of execution will be left to right.
// let msg = " I am a Programmer ";
// console.log(msg.trim().toUpperCase());
//Slice method - return the part of the original string as a new String
let name = "Shelley";
console.log(name.slice(0));
console.log(name.slice(0,4));
console.log(name.slice(-3));
//string concatenation
// str1.concat(str2);
//string replace
// str.replace(searchVal , newVal);
// To know the value of wanted index
// str.charAt(idx);