-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings-properties.js
More file actions
70 lines (42 loc) · 1.59 KB
/
strings-properties.js
File metadata and controls
70 lines (42 loc) · 1.59 KB
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
//* String Properties
//? String Consructor
// the String constructor is used to create a new string object. When called instead as a fucntion, it performs type conversion to a primitive string, which is usally more usefull
//! syntax
// new String(text)
// String(text)
//! Note -: string() can be called with or whthout new, but with different effects.
const a = new String("text");
const b = String("text");
console.log(a instanceof String); // true
console.log(b instanceof String); // false
console.log(typeof a); // object
console.log(typeof b); // string
//? string Prototype
// the protoype is a property available with all javascript objects.
// the prototype property allows you to add new properties and methods to string.
//* syntax
// Object.prototype.name = value;
function Movie(name, revenue) {
(this.name = name), (this.revenue = revenue);
}
const newMovie = new Movie("Endgame", "1.9B");
Movie.prototype.company = "Marvel";
console.log(newMovie.company); // Marvel
//? string Length
// A Function object's length property indicates the number of parameters expected by the function.
function func1() {}
function func2(a, b) {}
console.log(func1.length);
// expected output: 0
console.log(func2.length);
// expected output: 2
//
console.log(Function.length); // 1
console.log((() => {}).length); // 0
console.log(((a) => {}).length); // 1
console.log(((a, b) => {}).length); // 2 etc.
console.log(((...args) => {}).length);
// 0, rest parameter is not counted
console.log(((a, b = 1, c) => {}).length);
// 1, only parameters before the first one with
// a default value are counted