Categories
JavaScript jQuery Web

JQuery Check if Checkbox is checked – Simple Solution

For a check box with the id “checkbox”, here is how to check if its checked:

$('#checkbox').is(':checked'); // Returns True if checked else False

Categories
JavaScript Web

JavaScript Basics: How to check for null & undefined

To check if a variable(a) has the value null, use the following code:

if (a === null) // Best way to do it!

if (a == null) // This does return true if a is null but it returns true also if a is undefined... so avoid it

To check if a variable(a) has the value undefined, use the following code:

if (typeof a === "undefined") // This works

if (a === undefined) // This works too

if (a == undefined) // This does return true if a is undefined but it returns true also if a is null... so avoid it