?
Solved

print_r equivalent

Posted on 2013-12-15
2
Medium Priority
?
151 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

765 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