ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
JavaScript Tutorial - Index
JavaScript Tutorial - Introduction to JavaScript
JavaScript Tutorial - Basic JavaScript Concepts
JavaScript Tutorial - Working with Operators and Variables
JavaScript Tutorial - How to work with Loops and Functions?
JavaScript Tutorial - How to work with Forms and Events?
JavaScript Tutorial - How to work with Objects?
JavaScript Tutorial - How to work with Browsers and Cookies?
JavaScript Tutorial - More about Objects
JavaScript Tutorial - How to validate Forms with JavaScript?
JavaScript Tutorial - Advanced Techniques in JavaScript
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > JavaScript Tutorial > Working with Operators and Variables
 

JavaScript Tutorial - Working with Operators and Variables

 
Page 1 of 3
 
Overview
 
In this chapter you will learn :
  • What are variables?
  • Various datatypes supported by JavaScript.
  • Scope of variables.
  • Naming variables
  • Various operators and expressions.

 

 

Working with Operators and Variables

JavaScript offers the same programming capabilities found in most programming languages like creating variables, constants, programming constructs, user defined functions and so on. Variables are used to store values that can be used in other parts of a program. Variables always have a name associated with them through which they can be referenced later. So, a variable is a named memory location that is used to hold data which can be modified by the program.

  • Variable names can begin with an uppercase letter (A through Z), lowercase letter (a through z), and underscore character( _ ) or dollar sign character( $ ).

  • The remaining characters can consist of letters, the underscore character, the dollar sign character or digits 0 to 9.

  • Variable names are case sensitive.

  • JavaScript does not allow the data type of the variable to be declared when a variable is created.

JavaScript supports four primitive types of values and supports complex types such as arrays and objects. Variables supported by JavaScript consists of :

Number

It consists of integer and floating point numbers and the special NaN (Not a Number) value.
Integer variables can also be represented in JavaScript in decimal, hexadecimal, and octal form.
But hexadecimal and octal integers are converted to decimal before they are displayed.
Floating-point literals require the use of either a decimal point or an integer followed by an exponent.
                 For example: 39, 12.25, -220, -34.54, 23E4

Boolean

  • It consists of logical values true and false.

  • Logical operators can be used in Boolean expressions.

  • JavaScript automatically converts the Boolean values true and false into 1 and 0, respectively, when used  with numerical expressions.

String

  • It consists of string values that are enclosed in single or double quotes.

  • A string is a sequence of zero or more characters.

  • If a string begins with a single quote, it must end with a single quote.

  • If a string begins with a double quote it must end with a double quote.


                 For example : "JavaScript", 'House number-67'

Null  

  • It consists of a single value, i.e., null.
  • Null identifies an empty or nonexistent reference.
  • The use of null value prevents the errors from using uninitialized variables.

Creating Variables

Variables can be declared using 'var' command. Although it is possible to declare variables by simply using them, declaring them ensures that programs are well organized and helps keep track of the scope of the variables. You can also simultaneously declare as well as assign value to the variable. The syntax for declaring variable is :

Syntax
var < variable name > = value ;
 
Example
var name;
                          var address = "house no. 88";
                          var pincode = 110044;s

Arrays

  • Arrays are JavaScript objects that are capable of storing a sequence of values. 

  • An array is an indexed list of elements or group of related variables.

  • The length of an array is the number of elements that an array contains.

  • The individual elements of an array are accessed by using the name of the array followed by the index value.

  • The array element index starts with 0.

  • The last array element index number is one less than the length of the array.
    An array must be declared before it is used.

  • Array can be declared as : 
    arrayName = new Array ( Array Length)   or
    arrayName = new Array( )

JavaScript automatically extends the length of an array when new array elements are initialized.

Example
Students = new Array ( 35 ) ;
                         Stud_Name[2] = "James"
 

 

       

 

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2015. All Rights Reserved.