- [Instructor] The data we store and use in variables in JavaScript falls into six primitive data types. Three we use all the time, numeric, string and Boolean, one we use occasionally, null, one fallback, undefined, and a new one introduced in ECMAScript 2015 called symbol, which we won't cover in this course. The numeric data type handles numbers. To store a numeric data type in a variable, simply assign a number to it. It can be any regular number, so one, two, three, 56, 3,847, it can be 3.1492, etc. It can be any negative number, so minus one, or minus 10, or minus 56.39, or minus 100 billion. Now, technically there is a limit to how big the number can be, but it's ridiculously high. So for all intents and purposes, whatever number you put in a variable will work as a numeric data type. The string that type handles strings of letters and symbols, what we commonly refer to as words and sentences. To store a string data type in a variable, wrap your string of text in straight quotation marks. You can use single or double quotes, just make sure you use the same one at the beginning and at the end. You can place any symbol between these quotation marks, but when you use hyphens or quotes in your text, you have to be extra careful. If you use straight double quotes to denote the beginning and end of the string, and then use straights double quotes in the string as well, everything breaks because you're terminating the string early. To fix this, you could use single straight quotes for the string and double quotes inside, but that would just trigger the same problem with apostrophes. To resolve this problem properly, escape the string quotes by placing a backslash in front of each of them. This tells the browser, "This straight quote is not part of the script, "treat it like regular text, "and everything will be just fine." The Boolean data type handles the binary true/false. To store a Boolean data type in the variable, type in true or false, without quotation marks. These are JavaScript commands, and will be understood by the browser. The same goes for the null data type, the null data type is the intentional absence of an object value. So if we want a variable to be empty, but not undefined, you set its value to null, without quotation marks as well. The undefined data type is what you get when you create a variable, but don't set it to anything. As you've learned, JavaScript is a weekly type language. So the data types are applied when you set the content in a variable. If you ever want to know what data type of variable has, you can use the typeof operator to find out. In the Exercise Files for this movie, 03_02, you'll find a bunch of variables. If you open the index.HTML file from the Exercise Files in the browser, open the console and type in, console log, and then typeof, followed by the variable name, you'll get the data type for the content within that variable. So we can say negInteger, this returns a number. Or you can say escQuote, this returns a string. We can say theSunIsWarm, that's a Boolean, emptyInside, that registers as an object, that is an error in the browser itself, that is the null value, but it's treated like an object 'cause the browser doesn't understand, 'cause there's literally nothing there. And finally, justAnotherVariable, which was undefined is undefined.
Author
Updated
4/1/2019Released
5/17/2017Through practical examples and mini-projects, this course helps you build your understanding of JavaScript piece by piece, from core principles like variables, data types, conditionals, and functions through advanced topics including loops, closures, and DOM scripting. Along the way, you will also be introduced to some ES6 and the basics of JavaScript libraries.
- What is JavaScript?
- Working with data
- Using functions and objects
- Working with JavaScript and the DOM
- Changing DOM elements
- Handling events
- Working with loops
- Making images responsive using markup
- Troubleshooting code
- Validating functionality
- Minifying JavaScript
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 7s
-
-
1. JavaScript: An Introduction
-
What is JavaScript?2m 38s
-
-
2. The Basics
-
Introducing the browser console10m 31s
-
3. Working with data
-
Data types in JavaScript4m 2s
-
Arrays2m 20s
-
4. Functions and Objects
-
Functions in JavaScript3m 28s
-
Build a basic function3m 29s
-
Anonymous functions5m 11s
-
Variable scope3m 17s
-
ES2015: let and const6m 12s
-
Make sense of objects3m 19s
-
Object constructors6m 16s
-
Closures8m 11s
-
-
5. JavaScript and the DOM, Part 1: Changing DOM Elements
-
Access and change elements4m 33s
-
Access and change classes3m 45s
-
Access and change attributes4m 53s
-
Add DOM elements6m 56s
-
6. Project: Create an Analog Clock
-
Use CSS to move clock hands3m 49s
-
7. JavaScript and the DOM, Part 2: Events
-
What are DOM events?1m 31s
-
Some typical DOM events1m 59s
-
Add and use event listeners6m 51s
-
-
8. Project: Typing Speed Tester
-
Rundown of HTML markup2m 58s
-
Build a count-up timer5m 56s
-
Add a reset button5m 3s
-
-
9. Loops
-
Loops3m 37s
-
Looping through arrays4m 7s
-
Break and continue loops7m 9s
-
-
10. Project: Automated Responsive Images Markup
-
Project breakdown1m 55s
-
Rundown of project setup3m 26s
-
-
11. Troubleshooting, Validating, and Minifying JavaScript
-
Troubleshooting JavaScript7m 20s
-
Online script linting5m 57s
-
Automate script linting8m 24s
-
Online script minification2m 50s
-
Automate script minification2m 24s
-
12. Bonus Chapter: Ask the Instructor
-
What are arrow functions?3m 11s
-
What does the % symbol do?3m 47s
-
-
Conclusion
-
Next Steps1m 55s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Data types in JavaScript