0
var map = new naver.maps.Map('map', mapOptions);

var latlng = map.getCenter();
console.log("latlng variable is ", latlng);

I'm using an external API (NAVER map, which is similar to Google map I believe) which runs on Javascript and I'm looking for a way to check a Javascript variable, to debug.

I want to know the value inside latlng but I can't see any log on my terminal. I googled and read that passing Javascript variable to ruby controller cannot be done directly. However, I'm not trying to pass the variable - I just want to see what's in it.

How can I do this? I can really use some help.

2
  • Did you tried looking into browser console? Normally console.log prints the out to the console. Commented Aug 13, 2017 at 13:04
  • 1
    This javascript runs client-side. Ruby runs server-side. console.log will print in the browser log, whereas Rails.log will print in the server log. Commented Aug 13, 2017 at 13:10

2 Answers 2

1

Open the browser console. The method for this varies between operating system and browser, but for example on Chrome you can press Ctrl+Shift+J (Windows / Linux) or Cmd+Opt+J (Mac).

In general, you should be able to do something like: Right click --> inspect --> console.


Your JavaScript code above is running on the client side, i.e. in the browser itself. In order to see any log messages, you need to look at the browser log.

This is in contrast to the rails code, which is running on the server side. Rails logs appear on the server itself, because that code is not executed by the browser.

I can't see anything wrong with your code, given the information provided. Take a look at the browser log, to see the value of the variable. You can also, for example, set breakpoints in the code - so you wouldn't need to explicitly write console.log each time.

Sign up to request clarification or add additional context in comments.

1 Comment

I only checked the server log on my c9 ide but now I can see all the logs on my Chrome browser's console. I just finished Codeacademy JS course so I wasn't aware of codes running on which side. Thank you very much!
0

Please try rewrite your 'console.log' like this:

var latlng = map.getCenter();
console.log("latlng variable is "+ latlng);

Change ',' to '+'. Then see if you see any latlng value on browser log

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.