JavaScript Variables Like other programming languages, JavaScript variables are a container that contains a value - a value that can be changed/fixed.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
Friday, Week 2 Variables! What’s a variable??? How do I use them in JavaScript??? What are they good for??? Some examples… Mini-Lab 2!!!
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Variables, Assignment & Math Storing and naming data.
2440: 211 Interactive Web Programming Expressions & Operators.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
VARIABLES & CONSTANTS. Objective By the end of the lesson students should be able to:  Define a constant  Define a variable  Understand the rules for.
CPS120: Introduction to Computer Science
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
CS346 Javascript -3 Module 3 JavaScript Variables.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Primitive Variables.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part One.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
Welcome to AP Computer Science A We use the Java language, but this class is much more rigorous than Intro to Java More programming, but also more theory.
CPS120: Introduction to Computer Science Variables and Constants.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Variables. Some Rules of Variable Naming Convention : Variable names are case-sensitive. A variable’s name can be any legal identifier. It can contain.
Chapter 5. Outline Some Exercises in C++ Names Variables Scope Lifetime.
C BASICS QUIZ (DATA TYPES & OPERATORS). C language has been developed by (1) Ken Thompson (2) Dennis Ritchie (3) Peter Norton (4) Martin Richards.
Chapter 2. Variable and Data type
JavaScript and Ajax (JavaScript Basic) Week 2 Web site:
Department of Electronic & Electrical Engineering Statements Blocks{} Semicolons ; Variables Names keywords Scope.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 4 – Simple Variable Types Modern JavaScript Design And Develop Copyright © 2012 by Larry.
Learning Javascript From Mr Saem
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
Introduction to Python Lesson 2a Print and Types.
Client-side (JavaScript) Validation. Associating a function with a click event – Part 1 Use the input tag’s onclick attribute to associate a function.
Constants, Data Types and Variables
INTRODUCTION TO C LANGUAGE
Chapter 6 JavaScript: Introduction to Scripting
CHAPTER 4 CLIENT SIDE SCRIPTING PART 1 OF 3
Overview of c# Programming
Data Types, Identifiers, and Expressions
Revision Lecture
trigraph ??= is for # ??( is for [ ??< is for { ??! is for |
JavaScript.
Unit-1 Introduction to Java
C++ Data Types Data Type
The Internet 11/15/11 Handling Data in JavaScript
Variables Kevin Harville.
JavaScript Variables.
Java Script Siddharth Srivastava.
Primitive Types and Expressions
Understanding Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Basic Programming Lab C.
Lecture 9: JavaScript Syntax
JavaScript Variables.
Presentation transcript:

JavaScript Variables Like other programming languages, JavaScript variables are a container that contains a value - a value that can be changed/fixed as required.

Declaring JavaScript variables First, you need to declare your variables. You do this using the var keyword. You can declare one variable at a time or more than one. You can also assign values to the variables at the time you declare them.

Declaring JavaScript variables // declaring one JavaScript variable var firstName; // declaring multiple JavaScript variables var firstName, lastName; // declaring and assigning one JavaScript variable var firstName = 'Homer'; // declaring and assigning multiple JavaScript variables var firstName = 'Homer', lastName = 'Simpson';

Using JavaScript variables Although there are many uses for JavaScript variables, here is a quick and simple example: var firstName = prompt("your first name?", ""); document.write(firstName);

Rules for JavaScript Variables 1.JavaScript variables' names can contain any letter of the alphabet, digits 0-9, and the underscore character. 2.No spaces 3.No punctuation characters (e.g comma, full stop, etc) 4.The first character of a variable name cannot be a digit. 5.JavaScript variables' names are case-sensitive. For example: firstName and FirstName are two different variables.

Example Variables and Constants Variables and Constants var amountDue; amountDue = 0; var productPrice = 5; var quantity = 2; amountDue = productPrice * quantity; alert ( amountDue );