Michael_Scharf
Michael_Scharf

Reputation: 34568

Can I create an iPython notebook using JavaScript as the language in the cells?

I love IPython to explain algorithms in python. But I want to do the same using javascript. Is it possible to write a notebook where I use javascript as the cell language?

Upvotes: 6

Views: 3259

Answers (1)

Amit
Amit

Reputation: 20516

You can use the %%javascript magic function for running javascript in IPython notebook. For example Paste the following code in a IPython cell and run it. You should see the output in your browser's javascript console.

%%javascript
console.log("Hello World!")

For global variables, you can add an attribute to the windows object for example, in a cell run the following code:

%%javascript
window.myvar = 12;

In another cell, run the following code and check browser's javascript console. The variable's value should be printed.

%%javascript
console.log(myvar)

Use the element variable for printing in the cell output area as shown below:

%%javascript
element.append(myvar)

Upvotes: 8

Related Questions