Canvas | Sololearn: Learn to code for FREE!



When ever I write this statement var c = canvas.get context("2d"); it gives me error why is there any mistake or compiler problem I have seen many programs in which it gives error "get context of null"

4 Answers

New Answer


Write your js code in onload=()=>{ //Write your code }


If you're getting "cannot access property getContext of null" or something like that then most probably, your program is not able to select the canvas element. Make sure that your code is inside the window.onload function and that you are selecting the canvas element in the correct way. No one can say much till you post your full code.


TheCoder ŚĄŃ XXX thanks friends I will next time use and see output thanks😉😉😉😃😃😃😇


Maybe you made a typo! Don't worry, I do a lot lol 🤣🤣🤣 I just Googled it, and it's supposed to be canvas.getContext("2d"); without space and the C is capital! Hope it works! :)