Home Web Front-end JS Tutorial JavaScript Notebook First Edition(Node.js)

JavaScript Notebook First Edition(Node.js)

Sep 08, 2024 pm 08:30 PM

JavaScript Notebook First Edition(Node.js)

When talking about Notebooks, Python users often think of Jupyter Notebook. Jupyter Notebook is a widely-used interactive computing environment with broad applications in data analysis, visualization, and machine learning. After using Python Notebooks, I became interested in how to run JavaScript in a Notebook. In the JavaScript Notebook series, I'll be sharing some of my exploration experiences in this area.

An "interactive computing environment" refers to how it runs code. It's neither purely a command-line REPL nor simply executing a .js file. Notebooks combine the advantages of both the command-line and file-based approaches by using cells. (REPL: Read-Eval-Print Loop, such as running the node or python commands in the terminal.)

JavaScript Notebook First Edition(Node.js)

In a Notebook, code is written in individual cells, each functioning as an independent code block. You can run each cell separately and immediately see the results. Top-level variables defined in one cell can be accessed in other cells. When writing code in a cell, you benefit from IDE-like features such as autocomplete and syntax highlighting. By pressing Shift+Enter or clicking the run button, the code in the current cell is executed. If the output isn't correct, you can easily modify the code and rerun the cell.

Now, back to the main topic: how can we run JavaScript in a Notebook? Jupyter Notebooks support various magic commands, and with the %%script node magic command, we can execute JavaScript directly within the Notebook. (This requires Node.js to be installed; if it's already installed, you can run it right away.)

JavaScript Notebook First Edition(Node.js)

To use ESM syntax in a cell, you can add the -experimental-default-type module flag, which is supported in Node.js version 21 and above.

While this method is relatively simple and practical, it has the following limitations:

  • Syntax highlighting and autocomplete are not fully supported.
  • Variables cannot be referenced across cells.

In the upcoming JavaScript Notebook series, I will introduce other methods that offer a better experience. If you're interested in JavaScript Notebooks, stay tuned for more insights.


Magic commands that start with %% are called Cell Magic commands, and they apply to the entire cell. The %%script node command means that the code in the cell will be executed using the Node.js interpreter.

Jupyter Notebook also supports the %%js and %%javascript magic commands. Unlike %%script node, these two commands run JavaScript code on the front end of the Notebook, in a web page environment, meaning that console.log output won’t appear below the cell. Similar to %%js, there are also %%html and %%svg commands, which render their respective outputs directly below the cell.

A Notebook is essentially a JSON file with a .ipynb extension, and it requires a notebook-compatible editor to open. VSCode supports Notebooks.

The above is the detailed content of JavaScript Notebook First Edition(Node.js). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1595
276
Advanced Conditional Types in TypeScript Advanced Conditional Types in TypeScript Aug 04, 2025 am 06:32 AM

TypeScript's advanced condition types implement logical judgment between types through TextendsU?X:Y syntax. Its core capabilities are reflected in the distributed condition types, infer type inference and the construction of complex type tools. 1. The conditional type is distributed in the bare type parameters and can automatically split the joint type, such as ToArray to obtain string[]|number[]. 2. Use distribution to build filtering and extraction tools: Exclude excludes types through TextendsU?never:T, Extract extracts commonalities through TextendsU?T:Never, and NonNullable filters null/undefined. 3

Micro Frontends Architecture: A Practical Implementation Guide Micro Frontends Architecture: A Practical Implementation Guide Aug 02, 2025 am 08:01 AM

Microfrontendssolvescalingchallengesinlargeteamsbyenablingindependentdevelopmentanddeployment.1)Chooseanintegrationstrategy:useModuleFederationinWebpack5forruntimeloadingandtrueindependence,build-timeintegrationforsimplesetups,oriframes/webcomponents

What are the differences between var, let, and const in JavaScript? What are the differences between var, let, and const in JavaScript? Aug 02, 2025 pm 01:30 PM

varisfunction-scoped,canbereassigned,hoistedwithundefined,andattachedtotheglobalwindowobject;2.letandconstareblock-scoped,withletallowingreassignmentandconstnotallowingit,thoughconstobjectscanhavemutableproperties;3.letandconstarehoistedbutnotinitial

Generate Solved Double Chocolate Puzzles: A Guide to Data Structures and Algorithms Generate Solved Double Chocolate Puzzles: A Guide to Data Structures and Algorithms Aug 05, 2025 am 08:30 AM

This article explores in-depth how to automatically generate solveable puzzles for the Double-Choco puzzle game. We will introduce an efficient data structure - a cell object based on a 2D grid that contains boundary information, color, and state. On this basis, we will elaborate on a recursive block recognition algorithm (similar to depth-first search) and how to integrate it into the iterative puzzle generation process to ensure that the generated puzzles meet the rules of the game and are solveable. The article will provide sample code and discuss key considerations and optimization strategies in the generation process.

What is optional chaining (?.) in JS? What is optional chaining (?.) in JS? Aug 01, 2025 am 06:18 AM

Optionalchaining(?.)inJavaScriptsafelyaccessesnestedpropertiesbyreturningundefinedifanypartofthechainisnullorundefined,preventingruntimeerrors.1.Itallowssafeaccesstodeeplynestedobjectproperties,suchasuser.profile?.settings?.theme.2.Itenablescallingme

How can you remove a CSS class from a DOM element using JavaScript? How can you remove a CSS class from a DOM element using JavaScript? Aug 05, 2025 pm 12:51 PM

The most common and recommended method for removing CSS classes from DOM elements using JavaScript is through the remove() method of the classList property. 1. Use element.classList.remove('className') to safely delete a single or multiple classes, and no error will be reported even if the class does not exist; 2. The alternative method is to directly operate the className property and remove the class by string replacement, but it is easy to cause problems due to inaccurate regular matching or improper space processing, so it is not recommended; 3. You can first judge whether the class exists and then delete it through element.classList.contains(), but it is usually not necessary; 4.classList

What is the class syntax in JavaScript and how does it relate to prototypes? What is the class syntax in JavaScript and how does it relate to prototypes? Aug 03, 2025 pm 04:11 PM

JavaScript's class syntax is syntactic sugar inherited by prototypes. 1. The class defined by class is essentially a function and methods are added to the prototype; 2. The instances look up methods through the prototype chain; 3. The static method belongs to the class itself; 4. Extends inherits through the prototype chain, and the underlying layer still uses the prototype mechanism. Class has not changed the essence of JavaScript prototype inheritance.

Building a Design System with Storybook and React Building a Design System with Storybook and React Jul 30, 2025 am 05:05 AM

First, use npxstorybookinit to install and configure Storybook in the React project, run npmrunstorybook to start the local development server; 2. Organize component file structure according to functions or types, and create corresponding .stories.js files to define different states in each component directory; 3. Use Storybook's Args and Controls systems to achieve dynamic attribute adjustments to facilitate testing of various interactive states; 4. Use MDX files to write rich text documents containing design specifications, accessibility instructions, etc., and support MDX loading through configuration; 5. Define the design token through theme.js and use preview.js

See all articles