main.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
92
93
94
95
96
97
98
let name = "Python";
let version = "2.7";

// Single reference is enough to set property name/value
let literalLanguage = {
  name,
  version,
  // Properties with () {} are implied methods & don't require the function keyword
  hello() { return "Hello from " + this.name}
  }

console.log(literalLanguage);
console.log(literalLanguage.hello());

let javascriptCreator = 'Brandan Eich';
let pythonCreator = 'Guido van Rossum';

let placeholder = "echo";

// Properties can be dynamically assigned at initialization with []
let creatorNames = { 
     [pythonCreator]: 'Python',
     [javascriptCreator]: 'JavaScript',
     [placeholder](message) { return message} 
}

console.log(creatorNames);
console.log(creatorNames.echo("Hello there!"));

let vowels = { 
  'a': 'First vowel',
  'e': 'Second vowel',
  'i': 'Third vowel',
  'o': 'Fourth vowel',
  'u': 'Fifth vowel'
}

// Object can be deconstructed and assigned to variables by property name
let { a, e, i, o, u } = vowels;

// Variables available after object deconstruction
console.log(a,e,i,o,u);

// Object can also be deconstructed and assigned to custom variables assigned by property name
let { a: lettera, e: lettere, i: letteri, o: lettero, u: letteru} = vowels;

// Custom variables available after object deconstruction
console.log(lettera,lettere,letteri,lettero,letteru);


/** 
// ES5 variation 


var name = "Python";                                                     
var version = "2.7";                                                     

// Explictly declare property name/value                             
var literalLanguage = {                                                  
    name: name,                                                                       
    version: version,
    // Method properties require to explicitly declare the function() keyword
    hello: function() { return "Hello from " + this.name}       
};                                                                       

console.log(literalLanguage);  
console.log(literalLanguage.hello());                                        

var javascriptCreator = 'Brandan Eich';
var pythonCreator = 'Guido van Rossum';

var placeholder = "echo";

// Properties cannot be dynamically assigned at initialization 
var creatorNames = { }

// Properties can be dynamically assigned after initialization
creatorNames[pythonCreator] = 'Python';
creatorNames[javascriptCreator] = 'JavaScript';
creatorNames[placeholder] = function(message) { return message }

console.log(creatorNames);
console.log(creatorNames.echo("Hello there!"));

var vowels = { 
  'a': 'First vowel',
  'e': 'Second vowel',
  'i': 'Third vowel',
  'o': 'Fourth vowel',
  'u': 'Fifth vowel'
}

// Object must be deconstructed explictly
var a = vowels.a, e = vowels.e, i = vowels.i, o = vowels.o, u=vowels.u;

// Variables available after object deconstruction
console.log(a,e,i,o,u);
 */
Native Browser JavaScript