Print Var in JsFiddle

JavascriptJsfiddle

Javascript Problem Overview


How would I print something to the result screen in JsFiddle from my JavaScript. I can't use document.write(), it doesn't allow it, neither print.

What should I use?

Javascript Solutions


Solution 1 - Javascript

To be able to see output from console.log() in JSFiddle, go to External Resources on the left-side panel and add the following link for Firebug:

https://getfirebug.com/firebug-lite-debug.js

Example of the result after adding firebug-lite-debug.js

Solution 2 - Javascript

I have a template for this purpose; here is the code I use:

HTML

<pre id="output"></pre>

JavaScript

function out()
{
    var args = Array.prototype.slice.call(arguments, 0);
    document.getElementById('output').innerHTML += args.join(" ") + "\n";
}

Sample use (JavaScript)

out("Hello world!");
out("Your lottery numbers are:", Math.random(), 999, Math.PI);
out("Today is", new Date());

Solution 3 - Javascript

Try:

document.getElementById('element').innerHTML = ...;

Fiddle: http://jsfiddle.net/HKhw8/

Solution 4 - Javascript

Might not do what you do, but you can type

console.log(string)

And it will print the string into the console of your browser. In chrome push CTRL + SHIFT + J to open the console.

Solution 5 - Javascript

You can do this ---> http://jsfiddle.net/chY5y/

$('body').append(yourVariable); 

Solution 6 - Javascript

Now jsfiddle can do it from the scratch. Just go to Javascrpt --> Frameworks & extensions --> Jquery(edge) and check Firebug lite checkbox

Solution 7 - Javascript

document.body.innerHTML = "Your data";

Solution 8 - Javascript

With ES6 tricks could be

function say(...args)
{ 
    document.querySelector('#out').innerHTML += args.join("</br>");
}
say("hi","john");

Add only

 <span id="out"></span>

in HTML

Solution 9 - Javascript

Here's one alternative: http://jsfiddle.net/skibulk/erh7m9og/1/

document.write = function (str) {
    document.body.insertAdjacentHTML("beforeend", str);
}

document.write("¡hola mundo");

Solution 10 - Javascript

Just to add something that might be useful to some folks....

If you add the debugger console as shown above, you can access the scope by executing this:

scope = angular.element(document.querySelector('[ng-controller=MyCtrl]')).scope();

I find inspecting the scope directly easier than console.log, alert(), etc.

Solution 11 - Javascript

If you're using JSfiddle, you can use this library: https://github.com/IonicaBizau/console.js

Add a rawgit of the lib to your jsfiddle resources: https://cdn.rawgit.com/IonicaBizau/console.js/0ee8fcc4ea802247c5a7a8e3c6530ede8ade308b/lib/console.min.js

Then you can just add this in the HTML:
<pre class="console"></pre>

Initialize the console in your JS:
ConsoleJS.init({selector: "pre.console"});

Usage Example: See it on jsfiddle

ConsoleJS.init({selector: "pre.console"});

let b;

console.log('hello world');
console.log([{'a':10,'b':44}]);
console.log(typeof [1,2,3,4]);
console.log(50 +67);
console.log(b);

Solution 12 - Javascript

Use the alert() function:

alert(variable name);
alert("Hello World");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaritroperView Question on Stackoverflow
Solution 1 - JavascriptdavidkelleherView Answer on Stackoverflow
Solution 2 - JavascriptIQAndreasView Answer on Stackoverflow
Solution 3 - JavascriptFlame TrapView Answer on Stackoverflow
Solution 4 - JavascriptEupheView Answer on Stackoverflow
Solution 5 - JavascriptMohammad AdilView Answer on Stackoverflow
Solution 6 - JavascriptvkabachenkoView Answer on Stackoverflow
Solution 7 - JavascriptIgor VaschukView Answer on Stackoverflow
Solution 8 - JavascriptJohnPanView Answer on Stackoverflow
Solution 9 - JavascriptskibulkView Answer on Stackoverflow
Solution 10 - JavascriptNephView Answer on Stackoverflow
Solution 11 - JavascriptEmmanuel N KView Answer on Stackoverflow
Solution 12 - JavascriptAshutosh JhaView Answer on Stackoverflow