Solved

print_r equivalent

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

717 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