getUniformLocation: is uniform exists or not.

getUniformLocation returns WebGLUniformLocation object even if there is no uniform in program (for example, getAttribLocation returns -1 in this case).
How to check if an uniform really exists?

An easy way to test if it would exist would be by pulling the value of it and see what it returns.
tested with lesson1 of learningwebgl.

var uniformlocation = gl.getUniformLocation(shaderProgram, “uMVMatrix”);
var uniform = gl.getUniform(shaderProgram, uniformlocation);
uniform === WebGLFloatArray;

var uniformlocation = gl.getUniformLocation(shaderProgram, “ThisMatrixdoesn’texist”);
var uniform = gl.getUniform(shaderProgram, uniformlocation);
uniform === null;

Btw this is only tested in chromium but I believe this would be an easy way to find it.

var uniformlocation,uniform;
uniformlocation = gl.getUniformLocation(shaderProgram, NameOfUniformVariable);
if (uniformlocation !== -1){
uniform = gl.getUniform(shaderProgram, uniformlocation);
} else {
uniform = null;
}

if uniform now returns null then it means it doesn’t exist in that shader

This is tested in both minefield and chromium
hopefully the other browser work with this code too

Thanks, easywebgl.