SlideShare a Scribd company logo
2
Most read
3
Most read
8
Most read
JavaScript
Variables
Charles Russell
Bennu Bird Media
Statement and
Expressions
●
A Statement requests an action.
●
An Expression sets a value.
●
Variables are used in both
●
They are passed into functions and used to control
branching and iteration
●
They can be the target of the expression or the value
of the expression
– In computer books you may see L value and R Value when
referring to expressions
So What are they
●
A variable a just a place to put things you want to
use later. A good anology would be a box
●
In JavaScript anything can go into a box
●
In this language the boxes are a little magical
– Boxes can resize themselves to hold anything you put in
them.
– Dumping from one box into another makes what was
already the box you are dumping into vanish
Labeling the Boxes
●
To name a variable just type a name and set a
value. You will not only named it you have
created and sized it.
●
var myVariable=β€œSome really cool stuffβ€œ;
– Note the var while not required leaving it off has some
implications that we will get into later
●
Another word for name is identifier and in computer
books it is more common to use identifier.
●
In general you can use any name you want, but
there are a few rules
Whats in a name
●
In Javascript a name must begin with a letter _ or
$
●
Names beginning with _ are generally used by
the system
●
Names beginning with $ are commonly used by
libraries
●
After the first character you can use as many
letters and numbers $ and _ as you want after
that
●
Name are case sensitive Name and name are not
Forbiden Names
●
Use of these words as names will cause an error
abstract debugger final instanceof protected throws
boolean default finally int public transient
break delete float interface return true
byte do for let short try
case double function long static typeof
catch else goto native super var
char enum if new switch void
class export implements null synchronized volatile
const extends import package this while
continue false in private throw with
Names with Baggage
●
Some names are used by Javascript
implementations and while legal should be
avoided. A partial list is below for more go to
http://www.javascripter.net/faq/reserved.htm
alert clearInterval decodeURIComponent
all clearTimeout defaultStatus
anchor clientInformation document
anchors close element
area closed elements
Array confirm embed
assign constructor embeds
blur crypto encodeURI
button Date encodeURIComponent
checkbox decodeURI escape
Weak Typing
●
JavaScript is a weakly typed language
●
This does not mean that it is type unaware
●
This means that you do not have to declare the
type of the variable
Summary
●
Variables are used in statements and expressions
●
The are just a way to store things for later use
●
There are rules to names
●
You cant use reserved words as names
●
Some legal names are not a good Idea
●
Java Script is a weekly typed language
Next Datatypes

More Related Content

ODP
Datatype in JavaScript
PPSX
Javascript variables and datatypes
PPT
Java Script ppt
PPTX
Javascript functions
PPTX
Java script
PPT
Css Ppt
Datatype in JavaScript
Javascript variables and datatypes
Java Script ppt
Javascript functions
Java script
Css Ppt

What's hot (20)

PPSX
computer language - Html frames
PPTX
Css position
PPT
Introduction to JavaScript (1).ppt
PDF
Ruby on Rails Presentation
PPTX
Introduction to CSS
PPT
Html ppt
PDF
JavaScript - Chapter 15 - Debugging Techniques
PPT
Introduction to Javascript
PDF
jQuery for beginners
PPT
JavaScript & Dom Manipulation
PPTX
Introduction to Javascript
PPTX
Css and its types
PPT
Html forms
PPTX
Css ppt
PDF
CSS3 Media Queries
PPTX
Html5 tutorial for beginners
PDF
Fundamental JavaScript [UTC, March 2014]
PDF
Ruby on Rails Presentation
PDF
Interfaces .net
PPT
JavaScript - An Introduction
computer language - Html frames
Css position
Introduction to JavaScript (1).ppt
Ruby on Rails Presentation
Introduction to CSS
Html ppt
JavaScript - Chapter 15 - Debugging Techniques
Introduction to Javascript
jQuery for beginners
JavaScript & Dom Manipulation
Introduction to Javascript
Css and its types
Html forms
Css ppt
CSS3 Media Queries
Html5 tutorial for beginners
Fundamental JavaScript [UTC, March 2014]
Ruby on Rails Presentation
Interfaces .net
JavaScript - An Introduction
Ad

Similar to JavaScript Variables (20)

PDF
Grooming with Groovy
PDF
8 introduction to_java_script
PPTX
Learn To Code: Introduction to java
PDF
Clean Code
PDF
Introduction to Javascript and Typescript.pdf
PPT
JavaScript Introductin to Functions
PPTX
Groovy / comparison with java
PPT
Douglas Crockford Presentation Goodparts
PPTX
Dart programming language
PDF
Writing Readable Code
PPTX
Java (1).ppt seminar topics engineering
PPTX
Advanced javascript from zero to hero in this PPT
PPTX
Introduction to JavaScript - Web Programming
PPTX
Cp 111 lecture 3
PPTX
Computer programing 111 lecture 3
Β 
PPTX
Modern_2.pptx for java
PPTX
Java script basics
PPT
Javascript
PDF
02. Ruby Basic slides - Ruby Core Teaching
PPT
The JavaScript Programming Language
Grooming with Groovy
8 introduction to_java_script
Learn To Code: Introduction to java
Clean Code
Introduction to Javascript and Typescript.pdf
JavaScript Introductin to Functions
Groovy / comparison with java
Douglas Crockford Presentation Goodparts
Dart programming language
Writing Readable Code
Java (1).ppt seminar topics engineering
Advanced javascript from zero to hero in this PPT
Introduction to JavaScript - Web Programming
Cp 111 lecture 3
Computer programing 111 lecture 3
Β 
Modern_2.pptx for java
Java script basics
Javascript
02. Ruby Basic slides - Ruby Core Teaching
The JavaScript Programming Language
Ad

More from Charles Russell (9)

PPT
Js objects
PPT
JavaScript iteration
PPT
Open Source Software
PPT
JavaScript Tools and Implementation
PPT
JavaScript Operators
PPT
JavaScript Comments and Conditionals
PPT
JavaScript Introduction
PPT
JavaScript Data Types
PPTX
Extending drupal authentication
Js objects
JavaScript iteration
Open Source Software
JavaScript Tools and Implementation
JavaScript Operators
JavaScript Comments and Conditionals
JavaScript Introduction
JavaScript Data Types
Extending drupal authentication

Recently uploaded (20)

PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
Testing WebRTC applications at scale.pdf
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PDF
Introduction to the IoT system, how the IoT system works
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
E -tech empowerment technologies PowerPoint
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
presentation_pfe-universite-molay-seltan.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPT
tcp ip networks nd ip layering assotred slides
PptxGenJS_Demo_Chart_20250317130215833.pptx
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
Testing WebRTC applications at scale.pdf
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
Introduction to the IoT system, how the IoT system works
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
E -tech empowerment technologies PowerPoint
Cloud-Scale Log Monitoring _ Datadog.pdf
522797556-Unit-2-Temperature-measurement-1-1.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
Job_Card_System_Styled_lorem_ipsum_.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Slides PDF The World Game (s) Eco Economic Epochs.pdf
Design_with_Watersergyerge45hrbgre4top (1).ppt
introduction about ICD -10 & ICD-11 ppt.pptx
presentation_pfe-universite-molay-seltan.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline
tcp ip networks nd ip layering assotred slides

JavaScript Variables

  • 2. Statement and Expressions ● A Statement requests an action. ● An Expression sets a value. ● Variables are used in both ● They are passed into functions and used to control branching and iteration ● They can be the target of the expression or the value of the expression – In computer books you may see L value and R Value when referring to expressions
  • 3. So What are they ● A variable a just a place to put things you want to use later. A good anology would be a box ● In JavaScript anything can go into a box ● In this language the boxes are a little magical – Boxes can resize themselves to hold anything you put in them. – Dumping from one box into another makes what was already the box you are dumping into vanish
  • 4. Labeling the Boxes ● To name a variable just type a name and set a value. You will not only named it you have created and sized it. ● var myVariable=β€œSome really cool stuffβ€œ; – Note the var while not required leaving it off has some implications that we will get into later ● Another word for name is identifier and in computer books it is more common to use identifier. ● In general you can use any name you want, but there are a few rules
  • 5. Whats in a name ● In Javascript a name must begin with a letter _ or $ ● Names beginning with _ are generally used by the system ● Names beginning with $ are commonly used by libraries ● After the first character you can use as many letters and numbers $ and _ as you want after that ● Name are case sensitive Name and name are not
  • 6. Forbiden Names ● Use of these words as names will cause an error abstract debugger final instanceof protected throws boolean default finally int public transient break delete float interface return true byte do for let short try case double function long static typeof catch else goto native super var char enum if new switch void class export implements null synchronized volatile const extends import package this while continue false in private throw with
  • 7. Names with Baggage ● Some names are used by Javascript implementations and while legal should be avoided. A partial list is below for more go to http://www.javascripter.net/faq/reserved.htm alert clearInterval decodeURIComponent all clearTimeout defaultStatus anchor clientInformation document anchors close element area closed elements Array confirm embed assign constructor embeds blur crypto encodeURI button Date encodeURIComponent checkbox decodeURI escape
  • 8. Weak Typing ● JavaScript is a weakly typed language ● This does not mean that it is type unaware ● This means that you do not have to declare the type of the variable
  • 9. Summary ● Variables are used in statements and expressions ● The are just a way to store things for later use ● There are rules to names ● You cant use reserved words as names ● Some legal names are not a good Idea ● Java Script is a weekly typed language