Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Logic is an incredibly important part of programming. Typically languages will have a “boolean” data type with two values, “true” or “false”. In JavaScript, some of the behaviors that produce “truthiness” and “falsiness” can be confusing. In this workshop, you will be steeped in many of the different ways JavaScript takes into account booleans. Have a question? Ask in the Treehouse forums, or on Twitter!
Follow along by forking the workspace!
A couple of advanced examples of logic out in the wild:
From the jQuery Source
jQuery allows you to select dom elements by wrapping the element directly. For example, given the following html:
<div id="foobar"></div>
You could either select the div with css selections $('#foobar')
or you could select the element if you ended up with it in your code some how. That would typically look like this $(this)
. The logic to handle this is here in the jQuery source where there is a simple test to see if the "selector.nodeType" is truthy (e.g. NOT undefined).
From the d3 Source
In d3's the user is allowed to provide an object {}
or two strings as parameters. So, selection.attr({...})
or selection.attr('someatrribute', 'somevalue')
.
The code tests if the arguments.length
is less than 2
because if it is, that means that the user has probably provided an object. In this case arguments.length
would equal 1
.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up