var cars Saab Volvo BMW Array assigned by an array literal var person

Var cars saab volvo bmw array assigned by an array

This preview shows page 7 - 10 out of 24 pages.

var cars = ["Saab", "Volvo", "BMW"]; // Array assigned by an array literal var person = {firstName:John, lastName:Doe}; // Object assigned by an object literal JavaScript Functions JavaScript statements written inside a function, can be invoked many times (reused): Invoke a function = Call upon a function (ask for the code in the function to be executed). function myFunction(a, b) { return a * b; // returns the product of a and b } JavaScript is Case Sensitive In JavaScript all identifiers are case sensitive. The variables lastName and lastname , are two different variables. The functions myFunction and myfunction , are two different functions. JavaScript does not interpret Var; as var . It is common, in JavaScript, to use camelCase names. You will often see identifier names written like lastName (instead of lastname). JavaScript Scope 7
Image of page 7
Scope is the set of variables you have access to. In JavaScript, objects and functions, are also variables. In JavaScript, scope is the set of variables, objects, and functions you have access to. JavaScript has function scope: The scope changes inside functions. Local JavaScript Variables Variables declared within a JavaScript function, become LOCAL to the function. Local variables have local scope : They can only be accessed within the function. Example // code here cannot use carName function myFunction() { var carName = "Volvo"; // code here can use carName } Since local variables are only recognized inside their functions, variables with the same name can be used in different functions. Local variables are created when a function starts, and deleted when the function is completed. Global JavaScript Variables A variable declared outside a function, becomes GLOBAL . A global variable has global scope : All scripts and functions on a web page can access it. Example var carName = " Volvo"; // code here can use carName function myFunction() { // code here can use carName } Local variables are deleted when the function is completed. Global variables are deleted when you close the page. 8
Image of page 8
Common HTML Events Here is a list of some common HTML events: Event Description onchange An HTML element has been changed onclick The user clicks an HTML element onmouseover The user moves the mouse over an HTML element onmouseout The user moves the mouse away from an HTML element onkeydown The user pushes a keyboard key onload The browser has finished loading the page JavaScript Events HTML events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can "react" on these events. HTML Events An HTML event can be something the browser does, or something a user does. Here are some examples of HTML events: An HTML web page has finished loading An HTML input field was changed An HTML button was clicked Often, when events happen, you may want to do something.
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 24 pages?

  • Fall '19
  • JavaScript Introduction

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
section of an HTML page or both.\nYou can place any number of scripts in an HTML document.\nThe