For others who hit this page while searching for getContext
returning null, it can happen if you have already requested a different type of context.
For example:
var canvas = ...;
var ctx2d = canvas.getContext('2d');
var ctx3d = canvas.getContext('webgl'); // will always be null
The same is equally true if you reverse the order of calls.