<html>
<head>
<meta name="description" content="math.js | basic usage">
<title>math.js | basic usage</title>
<script src="https://unpkg.com/mathjs/lib/browser/math.js"></script>
</head>
<body>
<script>
// basic usage of math.js
//
// website: http://mathjs.org
// docs: http://mathjs.org/docs
// examples: http://mathjs.org/examples
// functions and constants
print(math.round(math.e, 3)); // 2.718
print(math.atan2(3, -3) / math.pi); // 0.75
print(math.log(10000, 10)); // 4
print(math.sqrt(-4)); // 2i
print(math.pow([[-1, 2], [3, 1]], 2)); // [[7, 0], [0, 7]]
print(math.derivative('x^2 + x', 'x')); // 2 * x + 1
// expressions
print(math.evaluate('0.2 + 0.1')); // 4
print(math.evaluate('12.7 cm to inch')); // 5 inch
print(math.evaluate('9 / 3 + 2i')); // 3 + 2i
print(math.evaluate('det([-1, 2; 3, 1])')); // -7
// chaining
var a = math.chain(3)
.add(4)
.multiply(2)
.done();
print(a); // 14
// helper function to output formatted results.
function print(value) {
var precision = 14;
document.write(math.format(value, precision) + '<br>');
}
</script>
</body>
</html>
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |