-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathsample047.html
More file actions
18 lines (14 loc) · 827 Bytes
/
sample047.html
File metadata and controls
18 lines (14 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html><html lang="en"><body><script>
// create string object using the new keyword and the String() constructor
var stringObject = new String('foo');
console.log(stringObject); // logs foo {0 = 'f', 1 = 'o', 2 = 'o'}
console.log(typeof stringObject); // logs 'object'
// create string literal/primitive by directly using the String constructor
var stringObjectWithOutNewKeyword = String('foo'); // without new keyword
console.log(stringObjectWithOutNewKeyword); // logs 'foo'
console.log(typeof stringObjectWithOutNewKeyword); // logs 'string'
// create string literal/primitive (constructor leveraged behind the scene)
var stringLiteral = 'foo';
console.log(stringLiteral); // logs foo
console.log(typeof stringLiteral); // logs 'string'
</script></body></html>