Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

print_r equivalent

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

604 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