Hi Istvan, I got the desired output on the terminal. However, it seems that the variable firstAcc resets its own value once the program exits the getAccounts() function (See the EDIT for reference). The web3.js documentation doesn't seem to explain why that is the case. Is there a way to overcome this problem? Sorry for asking such basic question, I really appreciate the help.
– potatoguyNov 29 '17 at 11:24

This is not a web3.js related issue rather just a regular javascript phenomena. The function which body is after the .then is called the callback function. In your edited question first the second console.log is executed and at the time of its execution indeed firstAccount is undefined, this is no surprise! However, when the callback function is returned and executed, obviously we will have the correct value in the firstAccount variable. I guess you should just get to know better callback functions. You could start at thousand places, there are plenty of good resources for Javascript
– István András SeresNov 29 '17 at 12:08

A more interesting question is, how do you get the 11th account address if you have 11+ accounts?
– GVizAug 1 '18 at 20:01

I believe "web3.eth.accounts" has been deprecated, no? In any case, it did not return the first account. When I print it on the console, it says "undefined." Thanks for answering though.
– potatoguyNov 29 '17 at 10:06