Comments on: Checking types in JavaScript https://j11y.io/snippets/checking-types-in-javascript/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: GeekFG https://j11y.io/snippets/checking-types-in-javascript/#comment-456 Wed, 14 Jan 2009 10:38:13 +0000 https://j11y.io/?p=408#comment-456 That’s why a added this link “http://docs.jquery.com/JQuery_Core_Style_Guidelines”.
When I want to check for an array I use jQuery.isArray(object).

Moreover Object.prototype is a better way for browsers compatibility than window[key] = function(){}

]]>
By: James https://j11y.io/snippets/checking-types-in-javascript/#comment-455 Wed, 14 Jan 2009 09:17:48 +0000 https://j11y.io/?p=408#comment-455 @GeekFG, did you read my post (or any of the other comments)? Typeof is okay for most cases but it reports certain types incorrectly. For example, this won’t work:

alert( typeof [1,2,3,4,5] ); // This should alert 'Array', not 'Object'
]]>
By: GeekFG https://j11y.io/snippets/checking-types-in-javascript/#comment-454 Wed, 14 Jan 2009 09:11:09 +0000 https://j11y.io/?p=408#comment-454 Why did you not simply use typeOf (http://docs.jquery.com/JQuery_Core_Style_Guidelines) ?

]]>
By: Gman https://j11y.io/snippets/checking-types-in-javascript/#comment-453 Wed, 14 Jan 2009 02:58:48 +0000 https://j11y.io/?p=408#comment-453 @James
ya, now I got it. Thank you

]]>
By: Ryan Townsend https://j11y.io/snippets/checking-types-in-javascript/#comment-452 Mon, 12 Jan 2009 19:37:43 +0000 https://j11y.io/?p=408#comment-452 Paul, those guidelines do prevent use of a switch() condition though, for better code-readability James’ method works nicely.

]]>
By: Pete https://j11y.io/snippets/checking-types-in-javascript/#comment-451 Mon, 12 Jan 2009 19:35:39 +0000 https://j11y.io/?p=408#comment-451 nice idea

]]>
By: Paul Irish https://j11y.io/snippets/checking-types-in-javascript/#comment-450 Mon, 12 Jan 2009 18:48:04 +0000 https://j11y.io/?p=408#comment-450 just for reference, here are the official recommendations for doing these in jQuery: http://docs.jquery.com/JQuery_Core_Style_Guidelines

]]>
By: James https://j11y.io/snippets/checking-types-in-javascript/#comment-449 Mon, 12 Jan 2009 17:36:54 +0000 https://j11y.io/?p=408#comment-449 Hi Gman!

‘===’ is known as the strict equality operator. It is normally used instead of the well known general equality operator (‘==’). The only difference is that the former checks for type and the latter doesn’t. It’s best practice to use the strict version for that very reason.

An example:

var realNumber = 999;
var numberInString = '999';
 
realNumber == numberInString; // TRUE
realNumber === numberInString; // FALSE
]]>
By: Gman https://j11y.io/snippets/checking-types-in-javascript/#comment-448 Mon, 12 Jan 2009 17:27:52 +0000 https://j11y.io/?p=408#comment-448 what does “===” mean?

]]>