SlideShare a Scribd company logo
1 of 38
Data Types and
                                   Variables
Doncho Minkov
Technical Trainer
http://minkov.it
Telerik Software Academy
http://academy.telerik.com
Table of Contents

1.   Data Types
         Integer
         Floating-Point
         Boolean
         String
1.   Declaring and Using Variables
       Identifiers
       Declaring Variables and Assigning Values



                                                     2
Data Types
How Computing Works?
 Computers are machines that process data

   Data is stored in the computer memory in
    variables
   Variables have name, data type and value
 Example of variable definition and assignment

 in JavaScript
                          Variable name

                 var count = 5;


                    Variable value
                                                  4
What Is a Data Type?
 A data type:

   Is a domain of values of similar characteristics
   Defines the type of information stored in the
    computer memory (in a variable)
 Examples:

   Positive integers: 1, 2, 3, …
   Alphabetical characters: a, b, c, …


                                                       5
JavaScript Data Types
 JavaScript is actually typeless language

   i.e. the type of a variable can be changed
   All the variables are declared with var
   var count = 5; //variable holding integer value
   var name = "Doncho Minkov"; //variable holding a string
   var mark = 5.25 //variable holding floating point number




                                                              6
Integer Types
What are Integer Types?



 Integer types:

   Represent whole numbers
   Have range of values, depending on the size of
    memory used




                                                     8
Integer Types - Example


 Integer type can hold numbers from

 -9007199254740992 to 9007199254740992
 var studentsCount = 5;
 var maxInteger = 9007199254740992;
 var minInteger = -9007199254740992;




                                                    9
Integer Types
   Live Demo
Floating-Point
What are Floating-Point Types?
 Floating-point types:

   Represent real numbers
   Have range of values and precision
   Can behave abnormally in the calculations




                                                12
Floating-Point Types

 Floating-point size depend on the platform

   the browser and the OS
 32-bit OS and browser have 32 bits for number,

 while 64-bit have 64 bits
   It is good idea to use up to 32-bit numbers
    Will always work on all platforms




                                                   13
Abnormalities in the
                   Floating-Point Calculations
 Sometimes abnormalities can be observed

 when using floating-point numbers
  Comparing floating-point numbers can not be
   performed directly with the == operator
 Example:

  var a = 1.0;
  var b = 0.33;
  var sum = 1.33;
  var equal = (a+b == sum); // False!!!
  console.log("a+b = "+ (a+b) + ", sum = "+ sum +
  ", sum == a+b? is " + equal);
                                                    14
Floating-Point and Decimal
   Floating-Point Types
         Live Demo
Boolean Type
The Boolean Data Type



 The Boolean data type:

  Has two possible values:
    true and false
  Is useful in logical expressions




                                              17
Boolean Values – Example
 Example of boolean variables taking values of

 true or false:

  var a = 1;
  var b = 2;
  var greaterAB = (a > b);
  console.log(greaterAB);    // False
  var equalA1 = (a == 1);
  console.log(equalA1);      // True



                                                  18
Boolean Type
   Live Demo
String Type
The String Data Type
 The string data type:

   Represents a sequence of characters

 Strings are enclosed in quotes:

   Both ' and " work
   var s = "Microsoft .NET Framework";

 Strings can be concatenated

   Using the + operator


                                             21
Saying Hello – Example
 Concatenating the two names of a person to

 obtain his full name:

   var firstname = "Ivan";
   var lastname = "Ivanov";
   Console.log("Hello, " + firstname + "!");

   var fullName = firstname + " " + lastname;
   Console.log("Your full name is " + fullname);



  NOTE: a space is missing between the two
   names! We have to add it manually
                                                   22
String Type
  Live Demo
p       q

                        i




Introducing Variables
What Is a Variable?
 A variable is a:

   Placeholder of information that can usually be
    changed at run-time
 Variables allow you to:

   Store information
   Retrieve the stored information
   Manipulate the stored information



                                                     25
Variable Characteristics
 A variable has:

   Name
   Type (of stored data)
   Value
 Example:

    var counter = 5;
   Name: counter
   Type: integer
   Value: 5
                                              26
Declaring And Using
Variables
Declaring Variables
 When declaring a variable we:

   Specify its name (called identifier)
   May give it an initial value
   The type is identified by the value
 The syntax is the following:

  var <identifier> [= <initialization>];


 Example:

  var height = 200;

                                                  28
Identifiers
 Identifiers may consist of:

   Letters (Unicode)
   Digits [0-9]
   Underscore "_"
   Dollar '$'
 Identifiers

   Can begin only with a letter or an underscore
   Cannot be a JavaScript keyword

                                                    29
Identifiers (2)
 Identifiers

   Should have a descriptive name
   It is recommended to use only Latin letters
   Should be neither too long nor too short
 Note:

   In JavaScript small letters are considered
    different than the capital letters (case
    sensitivity)


                                                  30
Identifiers – Examples
 Examples of correct identifiers:
  var New = 2; // Here N is capital
  var _2Pac; // This identifiers begins with _
  var поздрав = "Hello"; // Unicode symbols used
  // The following is more appropriate:
  var greeting = "Hello";
  var n = 100; // Undescriptive
  var numberOfClients = 100; // Descriptive
  // Overdescriptive identifier:
  var numberOfPrivateClientOfTheFirm = 100;

 Examples of incorrect identifiers:

  var new;      // new is a keyword
  var 2Pac;     // Cannot begin with a digit
                                                    31
Assigning Values
  To Variables
Assigning Values
 Assigning of values to variables

   Is achieved by the = operator
 The = operator has

   Variable identifier on the left
   Value of the corresponding data type on the
    right
   Could be used in a cascade calling, where
    assigning is done from right to left


                                                  33
Assigning Values – Examples
 Assigning values example:

  var firstValue = 5;
  var secondValue;
  var thirdValue;

  // Using an already declared variable:
  secondValue = firstValue;

  //   The following cascade calling assigns
  //   3 to firstValue and then firstValue
  //   to thirdValue, so both variables have
  //   the value 3 as a result:

  thirdValue = firstValue = 3; // Avoid this!

                                                34
Initializing Variables
 Initializing

   Is assigning of initial value
   Must be done before the variable is used!
 Several ways of initializing:

   By using a literal expression
   By referring to an already initialized variable


                                                      35
Initialization – Examples


 Example of some initializations:


   // This is how we use a literal expression:
   var heightInMeters = 1.74;

   // Here we use an already initialized variable:
   var greeting = "Hello World!";
   var message = greeting;




                                                     36
Assigning and
Initializing Variables
        Live Demo
Data Types and Variables




            http://academy.telerik.com

More Related Content

What's hot

Chapter 2 basic element of programming
Chapter 2 basic element of programming Chapter 2 basic element of programming
Chapter 2 basic element of programming
Zul Aiman
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
Shashwat Shriparv
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts
S Akai
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
Tony Apreku
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data types
Tuan Ngo
 

What's hot (20)

Data types and Operators
Data types and OperatorsData types and Operators
Data types and Operators
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
 
Cpprm
CpprmCpprm
Cpprm
 
Java Programming
Java Programming Java Programming
Java Programming
 
Chapter 2 basic element of programming
Chapter 2 basic element of programming Chapter 2 basic element of programming
Chapter 2 basic element of programming
 
Perl slid
Perl slidPerl slid
Perl slid
 
C# slid
C# slidC# slid
C# slid
 
Visula C# Programming Lecture 2
Visula C# Programming Lecture 2Visula C# Programming Lecture 2
Visula C# Programming Lecture 2
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 
Fundamental programming structures in java
Fundamental programming structures in javaFundamental programming structures in java
Fundamental programming structures in java
 
Variables and data types IN SWIFT
 Variables and data types IN SWIFT Variables and data types IN SWIFT
Variables and data types IN SWIFT
 
CSharp Language Overview Part 1
CSharp Language Overview Part 1CSharp Language Overview Part 1
CSharp Language Overview Part 1
 
Javascript
JavascriptJavascript
Javascript
 
Variables and data types in C++
Variables and data types in C++Variables and data types in C++
Variables and data types in C++
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts
 
Lecture 2 variables
Lecture 2 variablesLecture 2 variables
Lecture 2 variables
 
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...Data types in java | What is Datatypes in Java | Learning with RD | Created b...
Data types in java | What is Datatypes in Java | Learning with RD | Created b...
 
2 variables and data types
2   variables and data types2   variables and data types
2 variables and data types
 
C sharp chap2
C sharp chap2C sharp chap2
C sharp chap2
 

Similar to 02. Data Type and Variables

Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
ZubairAli256321
 
5. using variables, data, expressions and constants
5. using variables, data, expressions and constants5. using variables, data, expressions and constants
5. using variables, data, expressions and constants
CtOlaf
 

Similar to 02. Data Type and Variables (20)

02. Primitive Data Types and Variables
02. Primitive Data Types and Variables02. Primitive Data Types and Variables
02. Primitive Data Types and Variables
 
Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02Primitive Data Types and Variables Lesson 02
Primitive Data Types and Variables Lesson 02
 
03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...03 and 04 .Operators, Expressions, working with the console and conditional s...
03 and 04 .Operators, Expressions, working with the console and conditional s...
 
C# overview part 1
C# overview part 1C# overview part 1
C# overview part 1
 
CSC111-Chap_02.pdf
CSC111-Chap_02.pdfCSC111-Chap_02.pdf
CSC111-Chap_02.pdf
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
M C6java2
M C6java2M C6java2
M C6java2
 
Programming fundamental 02.pptx
Programming fundamental 02.pptxProgramming fundamental 02.pptx
Programming fundamental 02.pptx
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
JAVA LESSON-01.pptx
JAVA LESSON-01.pptxJAVA LESSON-01.pptx
JAVA LESSON-01.pptx
 
Lecture no 1
Lecture no 1Lecture no 1
Lecture no 1
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 
Java data types, variables and jvm
Java data types, variables and jvm Java data types, variables and jvm
Java data types, variables and jvm
 
5. using variables, data, expressions and constants
5. using variables, data, expressions and constants5. using variables, data, expressions and constants
5. using variables, data, expressions and constants
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 

More from Tommy Vercety

04. Conditional Statements
04. Conditional Statements04. Conditional Statements
04. Conditional Statements
Tommy Vercety
 
03. Operators - Expressions
03. Operators - Expressions03. Operators - Expressions
03. Operators - Expressions
Tommy Vercety
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
Tommy Vercety
 
00 JavaScript Part 1 Course - Introduction
00 JavaScript Part 1 Course - Introduction00 JavaScript Part 1 Course - Introduction
00 JavaScript Part 1 Course - Introduction
Tommy Vercety
 

More from Tommy Vercety (9)

09. Strings
09. Strings09. Strings
09. Strings
 
08. Objects
08. Objects08. Objects
08. Objects
 
07. Functions
07. Functions07. Functions
07. Functions
 
06. Arrays
06. Arrays06. Arrays
06. Arrays
 
05. Loops
05. Loops05. Loops
05. Loops
 
04. Conditional Statements
04. Conditional Statements04. Conditional Statements
04. Conditional Statements
 
03. Operators - Expressions
03. Operators - Expressions03. Operators - Expressions
03. Operators - Expressions
 
01 Introduction - JavaScript Development
01 Introduction - JavaScript Development01 Introduction - JavaScript Development
01 Introduction - JavaScript Development
 
00 JavaScript Part 1 Course - Introduction
00 JavaScript Part 1 Course - Introduction00 JavaScript Part 1 Course - Introduction
00 JavaScript Part 1 Course - Introduction
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

02. Data Type and Variables

  • 1. Data Types and Variables Doncho Minkov Technical Trainer http://minkov.it Telerik Software Academy http://academy.telerik.com
  • 2. Table of Contents 1. Data Types  Integer  Floating-Point  Boolean  String 1. Declaring and Using Variables  Identifiers  Declaring Variables and Assigning Values 2
  • 4. How Computing Works?  Computers are machines that process data  Data is stored in the computer memory in variables  Variables have name, data type and value  Example of variable definition and assignment in JavaScript Variable name var count = 5; Variable value 4
  • 5. What Is a Data Type?  A data type:  Is a domain of values of similar characteristics  Defines the type of information stored in the computer memory (in a variable)  Examples:  Positive integers: 1, 2, 3, …  Alphabetical characters: a, b, c, … 5
  • 6. JavaScript Data Types  JavaScript is actually typeless language  i.e. the type of a variable can be changed  All the variables are declared with var var count = 5; //variable holding integer value var name = "Doncho Minkov"; //variable holding a string var mark = 5.25 //variable holding floating point number 6
  • 8. What are Integer Types?  Integer types:  Represent whole numbers  Have range of values, depending on the size of memory used 8
  • 9. Integer Types - Example  Integer type can hold numbers from -9007199254740992 to 9007199254740992 var studentsCount = 5; var maxInteger = 9007199254740992; var minInteger = -9007199254740992; 9
  • 10. Integer Types Live Demo
  • 12. What are Floating-Point Types?  Floating-point types:  Represent real numbers  Have range of values and precision  Can behave abnormally in the calculations 12
  • 13. Floating-Point Types  Floating-point size depend on the platform  the browser and the OS  32-bit OS and browser have 32 bits for number, while 64-bit have 64 bits  It is good idea to use up to 32-bit numbers  Will always work on all platforms 13
  • 14. Abnormalities in the Floating-Point Calculations  Sometimes abnormalities can be observed when using floating-point numbers  Comparing floating-point numbers can not be performed directly with the == operator  Example: var a = 1.0; var b = 0.33; var sum = 1.33; var equal = (a+b == sum); // False!!! console.log("a+b = "+ (a+b) + ", sum = "+ sum + ", sum == a+b? is " + equal); 14
  • 15. Floating-Point and Decimal Floating-Point Types Live Demo
  • 17. The Boolean Data Type  The Boolean data type:  Has two possible values:  true and false  Is useful in logical expressions 17
  • 18. Boolean Values – Example  Example of boolean variables taking values of true or false: var a = 1; var b = 2; var greaterAB = (a > b); console.log(greaterAB); // False var equalA1 = (a == 1); console.log(equalA1); // True 18
  • 19. Boolean Type Live Demo
  • 21. The String Data Type  The string data type:  Represents a sequence of characters  Strings are enclosed in quotes:  Both ' and " work var s = "Microsoft .NET Framework";  Strings can be concatenated  Using the + operator 21
  • 22. Saying Hello – Example  Concatenating the two names of a person to obtain his full name: var firstname = "Ivan"; var lastname = "Ivanov"; Console.log("Hello, " + firstname + "!"); var fullName = firstname + " " + lastname; Console.log("Your full name is " + fullname);  NOTE: a space is missing between the two names! We have to add it manually 22
  • 23. String Type Live Demo
  • 24. p q i Introducing Variables
  • 25. What Is a Variable?  A variable is a:  Placeholder of information that can usually be changed at run-time  Variables allow you to:  Store information  Retrieve the stored information  Manipulate the stored information 25
  • 26. Variable Characteristics  A variable has:  Name  Type (of stored data)  Value  Example: var counter = 5;  Name: counter  Type: integer  Value: 5 26
  • 28. Declaring Variables  When declaring a variable we:  Specify its name (called identifier)  May give it an initial value  The type is identified by the value  The syntax is the following: var <identifier> [= <initialization>];  Example: var height = 200; 28
  • 29. Identifiers  Identifiers may consist of:  Letters (Unicode)  Digits [0-9]  Underscore "_"  Dollar '$'  Identifiers  Can begin only with a letter or an underscore  Cannot be a JavaScript keyword 29
  • 30. Identifiers (2)  Identifiers  Should have a descriptive name  It is recommended to use only Latin letters  Should be neither too long nor too short  Note:  In JavaScript small letters are considered different than the capital letters (case sensitivity) 30
  • 31. Identifiers – Examples  Examples of correct identifiers: var New = 2; // Here N is capital var _2Pac; // This identifiers begins with _ var поздрав = "Hello"; // Unicode symbols used // The following is more appropriate: var greeting = "Hello"; var n = 100; // Undescriptive var numberOfClients = 100; // Descriptive // Overdescriptive identifier: var numberOfPrivateClientOfTheFirm = 100;  Examples of incorrect identifiers: var new; // new is a keyword var 2Pac; // Cannot begin with a digit 31
  • 32. Assigning Values To Variables
  • 33. Assigning Values  Assigning of values to variables  Is achieved by the = operator  The = operator has  Variable identifier on the left  Value of the corresponding data type on the right  Could be used in a cascade calling, where assigning is done from right to left 33
  • 34. Assigning Values – Examples  Assigning values example: var firstValue = 5; var secondValue; var thirdValue; // Using an already declared variable: secondValue = firstValue; // The following cascade calling assigns // 3 to firstValue and then firstValue // to thirdValue, so both variables have // the value 3 as a result: thirdValue = firstValue = 3; // Avoid this! 34
  • 35. Initializing Variables  Initializing  Is assigning of initial value  Must be done before the variable is used!  Several ways of initializing:  By using a literal expression  By referring to an already initialized variable 35
  • 36. Initialization – Examples  Example of some initializations: // This is how we use a literal expression: var heightInMeters = 1.74; // Here we use an already initialized variable: var greeting = "Hello World!"; var message = greeting; 36
  • 38. Data Types and Variables http://academy.telerik.com

Editor's Notes

  1. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  2. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  3. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  4. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  5. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  6. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  7. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  8. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  9. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  10. * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##