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 JavaScript Number toExponential() method returns a string representing the Number object in exponential notation.
6
+
7
+
// The syntax of the toExponential() method is:
8
+
9
+
// num.toExponential(fractionDigits)
10
+
// Here, num is a number.
11
+
12
+
// Number toExponential() Parameters
13
+
// The toExponential() method takes in:
14
+
//
15
+
// fractionDigits (Optional) - An integer specifying the number of digits after the decimal point. By default, it is as many digits as necessary to specify the number.
16
+
// Return value from Number toExponential()
17
+
// Returns a string representing the given Number object in exponential notation, rounded to fractionDigits digits after the decimal point.
// If the same code snippet is used in various programs, then it is better to use Symbols in the object key. It's because you can use the same key name in different codes and avoid duplication issues. For example,
3
+
4
+
letperson={
5
+
name: "Jack"
6
+
};
7
+
8
+
// creating Symbol
9
+
letid=Symbol("id");
10
+
11
+
// adding symbol as a key
12
+
person[id]=12;
13
+
// In the above program, if the person object is also used by another program, then you wouldn't want to add a property that can be accessed or changed by another program. Hence by using Symbol, you create a unique property that you can use.
14
+
15
+
// Now, if the other program also needs to use a property named id, just add a Symbol named id and there won't be duplication issues. For example,
16
+
person={
17
+
name: "Jack"
18
+
};
19
+
20
+
letid1=Symbol("id");
21
+
22
+
person[id1]="Another value";
23
+
// In the above program, even if the same name is used to store values, the Symbol data type will have a unique value.
24
+
25
+
// In the above program, if the string key was used, then the later program would have changed the value of the property. For example,
26
+
27
+
person={
28
+
name: "Jack"
29
+
};
30
+
31
+
// using string as key
32
+
person.id=12;
33
+
console.log(person.id);// 12
34
+
35
+
// Another program overwrites value
36
+
person.id='Another value';
37
+
console.log(person.id);// Another value
38
+
// In the above program, the second user.id overwrites the previous value.
0 commit comments