The last line is printed if its an expression, except if the line ends with a semicolon.
let a = 1 + 1;
let b = a * 2;
b
// explicit call of pprint
pprint([{fubar:[]}])
// implicit printing
[{fubar:[]}]
ijs.display.json({fuu:"baR"});
let svg = `<svg fill="#000000" height="200px" width="200px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 471.701 471.701" xml:space="preserve"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"> <g> <path d="M433.601,67.001c-24.7-24.7-57.4-38.2-92.3-38.2s-67.7,13.6-92.4,38.3l-12.9,12.9l-13.1-13.1 c-24.7-24.7-57.6-38.4-92.5-38.4c-34.8,0-67.6,13.6-92.2,38.2c-24.7,24.7-38.3,57.5-38.2,92.4c0,34.9,13.7,67.6,38.4,92.3 l187.8,187.8c2.6,2.6,6.1,4,9.5,4c3.4,0,6.9-1.3,9.5-3.9l188.2-187.5c24.7-24.7,38.3-57.5,38.3-92.4 C471.801,124.501,458.301,91.701,433.601,67.001z M414.401,232.701l-178.7,178l-178.3-178.3c-19.6-19.6-30.4-45.6-30.4-73.3 s10.7-53.7,30.3-73.2c19.5-19.5,45.5-30.3,73.1-30.3c27.7,0,53.8,10.8,73.4,30.4l22.6,22.6c5.3,5.3,13.8,5.3,19.1,0l22.4-22.4 c19.6-19.6,45.7-30.4,73.3-30.4c27.6,0,53.6,10.8,73.2,30.3c19.6,19.6,30.3,45.6,30.3,73.3 C444.801,187.101,434.001,213.101,414.401,232.701z"></path> </g> </g></svg>`
ijs.display.svg(svg);
const sleep = ms => new Promise(r => setTimeout(r, ms));
console.log("pre sleep");
await sleep(1000);
console.log("post sleep");
press tab (ijs.display.svg or ijs.display.html are some of many possible completions)
ij
all toplevel variables (const/let/var) are accessible from other cells.
var fubar = 42;
let fubar_local=43;
function call_me(arg){
return arg;
}
let [fu,bar] = ['fu','bar'];
const {ping,pong} = {ping:1, pingpong:2, pong:3}
console.log(fubar);
console.log(fubar_local);
console.log(call_me(42));
console.log(fu,bar);
console.log(ping,pong);
within a cell, const cannot be reassigned, but it can be reassigned in another cell, or when the cell is re-executed.
const some_const_var = 42;
some_const_var
const some_const_var = 43;
some_const_var
import * as math from "https://cdn.jsdelivr.net/npm/mathjs@12.3.0/+esm"
let d = math.derivative('x^2 + x', 'x');
`${d}`
const {default: OpenAI} = await import('https://cdn.jsdelivr.net/npm/openai@4.26.0/+esm');
console.log(OpenAI.OpenAI);
import OpenAI from "https://cdn.jsdelivr.net/npm/openai@4.26.0/+esm"
import {default as fubar} from "https://cdn.jsdelivr.net/npm/openai@4.26.0/+esm"
new fubar.OpenAI()
import {
atan2, chain, derivative, e, evaluate, log, pi, pow, round, sqrt
} from 'https://cdn.jsdelivr.net/npm/mathjs@12.3.0/+esm'
sqrt(16)
To make live easier, we have some magic imports. To use magic import, they need to be enabled (they are enabled by default).
ijs.magic_imports.enabled = true
Once enabled, the import sources are automatically transformed to jsdelivr cdn links.
// no version
import * as math from 'mathjs'
math.sqrt(9)
// explicit version
import * as math_12_3_0 from 'mathjs@12.3.0'
math_12_3_0.sqrt(9)