02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoPrevious Video

Boolean

<p>True and false, the life story of the Boolean data type is that short. In programming we deal a lot with yes or no values, meaning we have to make decisions based on whether something is true or false: this is where Boolean steps in and eases our lives.</p> <p>We have already established the fact that Strings and Numbers are stored in variable var; so are Booleans. Let&rsquo;s look at some syntax first so we can determine how exactly they are declared. </p> <p><i>var isTotalJerk = false; var isFriend = true; </i></p> <p>This is the correct way of declaring and assigning values to a Boolean variable. If you&rsquo;re wondering how that differs from strings, the devil&#39;s in the details! If you look closely, we have not enclosed the words true and false in double quotation marks; if we had written &ldquo;true&rdquo; or &ldquo;false&rdquo; than they would have been stored as strings.</p> <h3>How do Booleans help us?</h3> <p>How do Booleans help us? We are going to learn another JavaScript function called &quot;<b>confirm();</b>&quot; Every now and then you will need to ask the user a simple yes/no question such as whether they want to continue doing something or not. This is where we use confirm(); it accepts a single string argument and displays a pop up box very similar to <b>alert();</b> except this pop-up box has two buttons which return either true or false. Let&rsquo;s look at the syntax first, then we will see its usage and advantage. </p> <p><i>var goAhead = confirm(&ldquo;Do you want to continue?&rdquo;); </i> </p> <p>This code will pop up a box on the user&#39;s screen where he can either click OK or CANCEL. OK stores True in goAgead while CANCEL stores False. </p> <p>An Important thing to note here is that the True and False values we are storing in the Boolean variable identify whether goAhead is empty or not. If we simply put strings in it such as &ldquo;True&rdquo; or &ldquo;False&rdquo; then the variable goAhead will always have something in it but it can&rsquo;t be efficiently used in an IF check (about which we are about to learn.) </p> <h3>Using Boolean with an IF check </h3> <p>Let&rsquo;s see how it&rsquo;s used. (If you&#39;renot familiar with the &ldquo;IF&rdquo; check you <b>really</b> must visit the <a href="/category/developer-basics">Developer Basics Section</a> and explore our basic developing tutorials; they are specially designed to teach you the details of programming fundamentals and the first one is free!)</p> <p><i>var goAhead = confirm(&ldquo;Do you want to continue?&rdquo;); </i></p> <p>This will store true or false in the variable. Now we can use it within our &#39;if check&#39; to help us take decisions like this:</p> <p><i>if (goAhead) {</i></p> <p> <i>alert(&ldquo;You want to go ahead to swim in that swamp full of alegators&rdquo;);</i></p> <p><i>}</i></p> <p><i>else </i></p> <p><i>alert(&ldquo;You DON&rsquo;T want to go ahead to swim as you are a baby&rdquo;);</i></p> <p><i>}</i></p> <p>What will the previous code do? If the user clicks OK, we&#39;ll see YOU WANT TO GO AHEAD, if the user clicks CANCEL we will see YOU DON&rsquo;T WANT TO GO AHEAD. That easy! Booleans are simple, but so very vital in programming &ndash; so please watch this video again if you don&#39;t completely understand the concept.</p>

Intro

It's never been easier to start learning programming in JavaScript. We live in an HTML5 world: what would be better than learning how to code with JavaScript and HTML5?

03:59

The Script Tag

You must know about script tags in order to code in JavaScript, so let’s jump into it and learn with style!

04:26

OOP and DOM

Two basics which are very important in programming and provide discipline which helps you learn and stay organized

02:45

What are Variables?

Variables are the building blocks of any language, so it's best to be very familiar with them and their usage.

01:37

Strings

Strings are an important part of programming; they can be manipulated, passed as parameters and a lot more.

10:39

Creating Javascript Comments

Comments are a great asset of programming. They will help make the code more understandable and manageable

00:52

Numbers

Math is everywhere; numbers are everywhere. JavaScript lets us use them and apply math on them, so let’s have fun and learn about Numbers in JavaScript.

09:29

Boolean

Booleans help us make important decisions in programming by proving yes or no information.

09:10