Learning to code ,

Learning to code ,

Hey guys , I kind of have a really weird question , recently i was just going through a small piece of code on Github and came across the following snippet : 

  1. // Internal functions, used to easily get values
  2.     this._getOpp = function(opp) { 
  3.       return {left: 'right', 
  4.       right: 'left', 
  5.       top: 'bottom', 
  6.       bottom: 'top',
  7.       x: 'y', 
  8.       y: 'x'}[opp]; 
  9.     };
it turns out , the above syntax is similar to switch case and is good for declaring internal methods in a plugin. (i got to know this on SO) . 

now i came across this syntax , not while coding , but while just reading through a library code(and trying to possible make some sense of the code). So basically i was't coding or writing code myself , i was just glancing through someone else's code and i ended up learning something new. 

coding is certainly the best way to learning , but is also checking out stuff(not coding .. just glancing through code or debugging a snippet already coded ) also a great way to learn JS(or any programming language for that matter ) ?  i know its a bit of a stupid question , but i just taught i would ask . Has it every occurred to you too that , you've learned something new , by just looking at how someone has coded a certain snippet or library ? 

Thank you