Download presentation
Presentation is loading. Please wait.
Published byLesley Butler Modified over 9 years ago
1
Copyright ©2005 Department of Computer & Information Science Introducing Variables
2
Copyright ©2005 Department of Computer & Information Science Goals By the end of this lecture you should … Understand what purpose a variable serves.Understand what purpose a variable serves. Understand primitive and composite data types.Understand primitive and composite data types. Understand why programmers assign data types to variables.Understand why programmers assign data types to variables.
3
Copyright ©2005 Department of Computer & Information Science Review: IPO INPUT: Gathering the necessary data that we need to produce viable information in our application.INPUT: Gathering the necessary data that we need to produce viable information in our application. PROCESSING: Manipulating that data.PROCESSING: Manipulating that data. OUTPUT: Giving back meaningful information back to our user.OUTPUT: Giving back meaningful information back to our user. Where do we store gathered data?Where do we store gathered data?
4
Copyright ©2005 Department of Computer & Information Science Variables We must store any data that we collect or process in memory. One of the data structures in which we store data is called a variable.We must store any data that we collect or process in memory. One of the data structures in which we store data is called a variable. A variable is a place in a computer's memory that can store a single value at any one time.A variable is a place in a computer's memory that can store a single value at any one time.
5
Copyright ©2005 Department of Computer & Information Science Variables vs. Constants We when store a value using a variable, we expect that value can, and often does, change.We when store a value using a variable, we expect that value can, and often does, change. We can also define a constant data structure whereby we expect the value to be static through the course of an application's run.We can also define a constant data structure whereby we expect the value to be static through the course of an application's run.
6
Copyright ©2005 Department of Computer & Information Science Reserving Memory When we want to reserve a spot in memory for a variable, we declare a variable.When we want to reserve a spot in memory for a variable, we declare a variable. When declaring a variable, we also need to identify that variable's data type …When declaring a variable, we also need to identify that variable's data type …
7
Copyright ©2005 Department of Computer & Information Science Declaring Data Type When we declare a data type, we specify which values a variable will hold.When we declare a data type, we specify which values a variable will hold. In JavaScript, we can declare primitive data types or composite data types.In JavaScript, we can declare primitive data types or composite data types.
8
Copyright ©2005 Department of Computer & Information Science Primitive Data Types Primitive data types serve as the building blocks for JavaScript.Primitive data types serve as the building blocks for JavaScript. There are three primitive data types:There are three primitive data types: –Number data type –String data type –Boolean data type
9
Copyright ©2005 Department of Computer & Information Science Composite Data Types Composite data types are derived from other types (many times, primitive types).Composite data types are derived from other types (many times, primitive types). JavaScript also includes some pre- defined composite data types, like the object data type and the array data type.JavaScript also includes some pre- defined composite data types, like the object data type and the array data type.
10
Copyright ©2005 Department of Computer & Information Science Why do we type? We declare data types in order to conserve resources. We only ask for the memory space that we need. For instance, if we only need enough memory to store a Boolean value, there is no sense to ask for enough memory to store a number type.We declare data types in order to conserve resources. We only ask for the memory space that we need. For instance, if we only need enough memory to store a Boolean value, there is no sense to ask for enough memory to store a number type.
11
Copyright ©2005 Department of Computer & Information Science Summary Variables are data structures that represent a place in a computer’s memory that hold a single value at any one time.Variables are data structures that represent a place in a computer’s memory that hold a single value at any one time. The value of a variable can, and often does, change.The value of a variable can, and often does, change. continued …
12
Copyright ©2005 Department of Computer & Information Science Summary A data type specifies which values a variable can hold.A data type specifies which values a variable can hold. Primitive data types are the building blocks of a language. Composite data types are complex data types derived from primitives.Primitive data types are the building blocks of a language. Composite data types are complex data types derived from primitives.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.