Hi Himanshu, its quite easy to access any JavaScript variable from the Selenium Webdriver test scripts. Just can simply use the below code snippet.
JavascriptExecutor JS = (JavascriptExecutor) webdriver;
// Get the current site title.
String sitetitle = (String)JS.executeScript("return document.title");
System.out.println("My Site Title: " + sitetitle);