6

I'm using VS Code, and was wondering if the Jupyter Notebook support also supports Javascript. Looking around online it looks like it should, but I am unable to produce any output.

This python code shows output "test":

print("test")

This JS code does not show any output:

%%javascript
console.log("test");

This JS code also does not show any output:

%%javascript
element.text("test");

And because I'm desparate, I've also tried this:

%%javascript
element.text = "test";

I have no clue what it is I am doing wrong...

VS Code, Python extension and Jupyter extension are all up to date.

3
  • have you found the solution? I'm having the same issue. Commented Feb 13, 2022 at 21:00
  • sadly, no answers found yet :-( Commented Feb 25, 2022 at 19:06
  • I posted an answer, not really sure if it works for you. Commented Feb 26, 2022 at 7:11

3 Answers 3

10

try using:

%%script node   
console.log("test");
Sign up to request clarification or add additional context in comments.

1 Comment

This works for Google Colab. Thank you very much.
2

In VSCode, the Javascript console is available through Help > Toggle Developer Tools, then on the Console tab. You'll see the console.log output appear (VSCode is based on Chromium, so it should be familiar if you ever used the Chrome JS console).

If you want the output to appear in the notebook, you can use javascript to update the HTML output, like:

%%html
<div id='abcd'></div>

<script>
var elem = document.getElementById('abcd');
elem.innerHTML = 'Some text';
</script>

Comments

0

I started using this extension and it is working perfectly.

https://marketplace.visualstudio.com/items?itemName=lostfields.nodejs-repl

I think it is not the same as Jupyter but it was enough for me.

1 Comment

The thing I like specifically about Jupyter Notebooks is that they are a sort of 'interactive documents', which is great for the introductory programming course I teach in high-school. It would be amazing for me if I can provide students with the same type of document when I want to switch to Javascript with them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.