var can = document.getElementById("canvas1"); var ctx = can.getContext("2d"); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

var can = document.getElementById("canvas1"); var ctx = can.getContext("2d");

What is can what is ctx

31st Oct 2016, 9:17 AM
Bhavya Pheena
Bhavya Pheena - avatar
2 Answers
+ 2
can is shortcut for canvas it is their choice we can name it fan man lan anything. ctx is shortcut for context. if we don't name it we will have to write that document.get... Everytime in the code instead we write can. and use in drawing
5th Nov 2016, 4:48 PM
Sandeep Chatterjee
+ 1
they are variables that you have just created and defined by using those 2 lines. 'var can' creates a variable (var) called 'can' which can then be used to assign some value to. In this particular case you assigned the HTML element 'canvas' to it by referencing to it through the 'document.getElementById' javascript code. after that you can actually use the 'can' variable every time you refer to the HTML canvas element. On initial definition you can call the variable whatever you like. 'can' or 'myCanvas' or 'whatever'.
22nd Dec 2016, 2:47 PM
John van den Elzen
John van den Elzen - avatar