Var ctx=c.getcontext() | Sololearn: Learn to code for FREE!


Var ctx=c.getcontext()

c is for getting context or ctx ?

8/9/2018 7:26:02 PM


5 Answers

New Answer


To make it more simple, in order to work with a canvas element that you have in HTML file, you have to do this in JavaScript: var can = document.getElementById("..."); var c = can.getContext("2d"); ***Note that variable names(can, c) can be chosen by you (you can change them as you wish).


ctx and c are just variable names they have nothing to do with canvas or context but here c would get the canvas element and ctx would access the canvas '2d' methods


thanks everyone.👍🙏


It can be assumed that 'c' is the variable for the page's Canvas element. If not, then that code is erroneous. var c = document.querySelector("#canvas"); var ctx = c.getContext("2d"); 'ctx' is used to grab the Context of Canvas.


if you are talking about creating a context for a canvas, c is the html DOM element of the canvas. Then you use getContext("2d") to get a context from the canvas element. 3d canvas is supposedly in work.