Solved

print_r equivalent

Posted on 2013-12-15
2
143 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now