Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
const canvas = document.getElementById("myCanvas"); const ctx = canvas.getContext("2d"); // The context object has all drawing methods console.log(typeof ctx.fillRect); // "function" console.log(typeof ctx.strokeText); // "function" // Canvas dimensions via the element console.log(canvas.width, canvas.height); // Clear the entire canvas ctx.clearRect(0, 0, canvas.width, canvas.height);
Result
Open