Solved

print_r equivalent

Posted on 2013-12-15
2
147 Views
Last Modified: 2013-12-31
Is it possible to dump a variable to the console, or alert box without just debugging?

Im trying to debug a JavaScript, but cant find out where it is executing. What I would like to do is something that I would usually do in PHP by print_r($myValirable);
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39720546
alert (myvariable);

Will either return a value, tell you it is an object, or tell you it is undefined.  Will that solve you problem?

If you need the properties of an object you can use: getOwnPropertyNames()
The use of getOwnPropertyNames() is definitively described here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames

Cd&
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 39720920
Pint to console is usually less obtrusive:
console.log(myvalue);

this will print whatever you want to the debugging console. (Hit F12 in any major browser)

Otherwise I like to use FireFox (with FireBug) for this.
1. I just run the website and hit F12.
2. Select FireBug's Script tab
    Now you have 2 options
    2.1. Search for the line you want and it will go through all scripts (file and in-line) to find it
    2.2. Select the file directly from the scripts list
    (I prefer the first)

3. Put a breakpoint in the line you want to inspect
4. Refresh the site


The execution will stop on the breakpoint and from there you can use the Stack tab (on the right inside the Script tab) to see the full call stack.


Btw, this is also possible in Chrome and maybe not as easy but also in IE.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question