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
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 Loops and Functions

JavaScript Tutorial - Working with Loops and Functions

Page 4 of 4
Passing Parameters

Functions may also be called with values, known as parameters, which may be used inside the body of the function. The function in which values are passed, is known as 'parameterized' function. Values are passed to the function by listing them in the parentheses following the function name. Both user-defined functions and built-in functions can accept parameters, process them and return values. During declaration, a function needs to be informed about the number of values that will be passed. Parameters exist only for the life of the function.

var x;
function cube( x )
                   document.write ( " Enter the number: " + x );
                   var cube = x * x * x;

Calling Function

Once a function has been declared, it can be called (or invoked ) in a script anywhere in an HTML page. Function is usually called in the BODY tag of the HTML page, and you usually pass a parameter into the function. The number of parameters being passed should be equal to the number of arguments the function has.

<SCRIPT LANGUAGE = "JavaScript">
var num;
function cube(num)
                return   num * num *num;



In this chapter you have learnt:

  • How looping helps controlling certain operations.
  • Different loop structures applicable at different situations.
  • Easier decision making through conditional constructs.
  • Skipping the loop construct through Break statement.
  • Accessing built-in functions.
  • Declaring and calling user-defined functions.



Review Questions

Fill in the Blanks

  1. ------- allows you to iterate a code in the program.
  2. ------- statement tests single expression, multiple times.
  3. The loop construct can be skipped using------- statement.
  4. Functions are declare and defined using the keyword----------.
  1. Loop
  2. Switch
  3. break
  4. function

True or False

  1. JavaScript functions may have no parameters.
  2. In the For loop, update expression can be negative.
  3. Do-while will always execute a block of code, at-least once.
  1. True
  2. True
  3. True
Sample Questions



  1. Calculate factorial of a number.
  2. Calculate power to a number through function
  3. What is the difference between While and Do-while Loop.


  1. View Code     View Runtime
  2. View Code    View Runtime
  3. Do-while loop will always execute a block of code once, no matter the condition is valid or not, whereas while loop will execute the statements only if the condition is true
What's Next

The next chapter will acquaint you with the concepts of JavaScript Events. The chapter will further elucidate various event handlers available in JavaScript and how to pop-up dialog boxes in the window.

                   Hop over to the next chapter to get the close-up of JavaScript Events and Dialog boxes.



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