-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20140428primativesOverWrappers.js~
63 lines (50 loc) · 1.12 KB
/
20140428primativesOverWrappers.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
//primatives over object wrappers
// js has five primative types: booleans, numbers, strings, null and undefined
> typeof null
'object'
//
> var s = new String("hello");
> typeof s
'object'
// s is an object that holds string "hello"
// how do we get the value from s after it was defined.
> s
{ '0': 'h',
'1': 'e',
'2': 'l',
'3': 'l',
'4': 'o' }
// so s is a hash of array addresses and coressponding values
> s [0]
'h'
> s + " world";
'hello world'
> s == "hello" // value equality
true
> s === "hello" // type equality
false
// we can use == with === to get value and then get type?
var s1 = new String ("hello");
> s == s1
false
> s === s1
false
// however we can have
> s1 [0] == s [0] // values are compared not objects
true
> s1 [0] === s [0] // values are compared and thier types
true
var s2 = new String ("world");
> s2
{ '0': 'w',
'1': 'o',
'2': 'r',
'3': 'l',
'4': 'd' }
> s1 [0] == s2 [0] // values are different
false
> s1 [0] === s2 [0] // types same but values different
false
// String prototype object has methods that can be called on a primatice
> "world".toUpperCase(); //
'WORLD'