Search engine will ignore the [ ] ", so I can't get the answer.
I took a test and find out they resulted the same, but I'm a js rookie and I don't know how they equals to each other.
            Asked
            
        
        
            Active
            
        
            Viewed 71 times
        
    0
            
            
         
    
    
        joseph
        
- 11
- 1
1 Answers
1
            
            
        fromCharCode 'lives' as a static method of the String Object. Such a method has a key and a value, visualised: {fromCharCode: function() {...}}. You can retrieve (access) the method using it's key directly String.fromCharCode or 'bracket' style String['fromCharCode']. This is true for all Objects.
The bracket notation may be usefull when the key contains special characters, see snippet.
const someObj = {
  dotNotation: 'hello world',
  'non dot Notation': 'hello world you too',
};
console.log(someObj.dotNotation);
// the last property can not be retrieved with dot notation
// console.log(someObj.non dot Notation);
// so
console.log(someObj['non dot Notation']); 
    
    
        KooiInc
        
- 119,216
- 31
- 141
- 177
- 
                    "static method of a `String` Object" -> "static method of the `String` Object". Otherwise it might confuse readers who don't know what "static" means. – David Knipe Apr 17 '22 at 11:48