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
Test Search by Job Title
Find a Personal Trainer
Job Resources
Free Self Tests and Quizzes
Find a Lawyer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Six Sigma Green Belt Certification
Lean Management Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
SEO Certification
Online Photography Course & Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Manangement Certification
Health Club Management Certification
Selling Skills Certification
Business Analysis Course
Green Living Course  free!
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
  All Online Courses
   

   
   
   
   
   
   

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

JavaScript Tutorial - Working with Operators and Variables

 
Page 3 of 3
 

Logical Operator

Logical operators are used to perform Boolean operations on Boolean operands. Logical operators, too, return true or false results based on the evaluation of the expression. Logical operators are:

      Operator

                              Description

                      Example

          &&

Logical and. If both Boolean operands on left and right side are true, only then the result is true, else false.

x = True ; y = False;
Result : False

          | |

Logical or. If either or both expressions evaluate to true, result is true.

x = True ; y = False;
Result : True

          !

Logical not. It negates the value of the Boolean expression.

x = True ; 
Result : False

     

Conditional Operator

Conditional operator is a ternary operator as it takes three operands. It is used to execute one of the two statements depending on condition. The conditional operator contains a condition to be evaluated, and two alternative values to be returned based on the truth or falsity of the condition.

Syntax
Condition ? Value 1 : Value 2

If the condition is true, value 1 is the result of the expression, otherwise value 2 is the result of the expression.

Example
   x = 5 ? odd : even.
                                     The result will be True.

String Operator

String operators are those operators that are used to perform operations on strings. Currently JavaScript supports only the 'string concatenation (+)'  operator.

Example
"Java" + "Script"  =  "JavaScript"

 

Sample question

If a= 10 and b=4, then print the value of 'a' after each of the following operations : 
a+=b             View Code            View Run time
a-=b             View Code            View Run time
a*=b             View Code             View Run time
a/=b             View Code             View Run time

 
 
Summary

In this chapter you have learnt:

  • How data is stored using variables.
  • Why naming of variables is important.
  • Local and Global scope of variables.
  • Various operators used in JavaScript.

 

 
Review Questions
 

Fill in the Blanks

  1. -------- are used to store values.
  2. Variables can be declared using ------ command.
  3. -------- operator takes one operand only.
  4. Conditional operator takes ------ operands.

 

Solutions

  1. Variables
  2. var
  3. Unary
  4. three

Check if following variable names are possible or not

  1. var Abc
  2. var XYZ
  3. var $aa
  4. var 1iu
  5. var __
  6. var $_1
  7. var aa aa

Solutions

  1. Valid variable name.
  2. Valid variable name.
  3. Valid variable name.
  4. Invalid variable name, because variable name cannot start with a number.
  5. Valid variable name.
  6. Valid variable name.
  7. Invalid variable name, because variable name cannot include space.
Exercise
If a= 10 and b=4, then print the value of 'a' after each of the following operations :
  1. a+=b
  2. a-=b
  3. a*=b
  4. a/=b
Solutions
  1. View Code            View Run time
  2. View Code            View Run time
  3. View Code            View Run time
  4. View Code            View Run time

 

 
What's Next


s The next chapter will acquaint you with the concepts of JavaScript programming through looping and functions. The chapter will further elucidate various loops available in JavaScript and how to create functions in JavaScript.

Hop over to the next chapter to get the close-up of JavaScript loops and functions.

         

       

 

 

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