Skip to content

Instantly share code, notes, and snippets.

@mcloide
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcloide/9219465 to your computer and use it in GitHub Desktop.
Save mcloide/9219465 to your computer and use it in GitHub Desktop.
Sometimes lack of knowledge in JS kills and this is why
$(document).ready(function(){
console.clear();
console.log('STARTING THE TEST');
var wrapper = $('#wrapper'),
enabled_1 = Boolean(wrapper.attr('data-feature-enabled')),
enabled_2 = Boolean(wrapper.data('feature-enabled')),
enabled_3 = Boolean(wrapper.prop('data-feature-enabled'));
console.log(enabled_1 + ': expected false');
console.log(enabled_2 + ': expected false - correct');
console.log(enabled_3 + ': expected false - correct? No! See bellow why.');
console.log("wrapper.prop('data-feature-enabled') is " + wrapper.prop('data-feature-enabled'));
console.log('TEST END');
});
/**
* This is what the console outputs:
* "STARTING THE TEST"
* "true: expected false"
* "false: expected false - correct"
* "false: expected false - correct? No! See bellow why."
* "wrapper.prop('data-feature-enabled') is undefined"
* "TEST END"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment