From the course: Computer Science Principles Lab: JavaScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Manage different variable types

Manage different variable types - JavaScript Tutorial

From the course: Computer Science Principles Lab: JavaScript

Start my 1-month free trial

Manage different variable types

- [Instructor] As you work with JavaScript, you will create and manipulate variables of many different types. JavaScript is a dynamically-typed language, meaning that you don't need to define what type a variable can hold. It will adapt to hold whatever value is assigned to it. But that doesn't mean you're off the hook. You still need to manage your variable types, or otherwise, you might get some odd results in your program. Let's walk through some examples of how you can manipulate your variables and control their value types. First, let's create a number. Var myVariable equals five. We can then create a string that will contain the value of the variable, and then we can use the typeof statement to tell us what type of value it is. Var msg, for message, equals myVariable is equal to, and then we'll concatenate myVariable. Then we'll concatenate another string, and is a. Then we'll add the evaluation typeof myVariable. Then, we can send that to the console. Save the file, and open…

Contents