1 / 20

Chapter 4: Fundamentals of JavaScript

4.1 Capabilities of JavaScript. Manage input and output.Permit information to be manipulated in a symbolic way, independent of how a particular computer stores that information internally.Perform arithmetic operations on numbers.Perform operations on and with strings of characters.Make decis

siobhan
Télécharger la présentation

Chapter 4: Fundamentals of JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Chapter 4: Fundamentals of JavaScript 4.1 Capabilities 4.2 Essential Terminology 4.3 Structure of JavaScript Code 4.4 Data and Objects 4.5 Tokens, Operators, Expressions, and Statements 4.6 The JavaScript math Object 4.7 Comparison Operators and Decision-Making Structures 4.8 Loop Structures 4.9 Using JavaScript to Change Values in Form Fields

    2. 4.1 Capabilities of JavaScript Manage input and output. Permit information to be manipulated in a symbolic way, independent of how a particular computer stores that information internally. Perform arithmetic operations on numbers. Perform operations on and with strings of characters. Make decisions based on comparing values. Perform repetitive calculations.

    3. 4.2 Some Essential Terminology

    4. 4.3 JavaScript Statements Usually embedded inside script tags. Built from tokens. Each statement should terminate with a semicolon. Statements are "free format" and can appear anywhere on a line. Multiple statements on a line are allowed if each is terminated with a semicolon. Statement blocks begin and end with curly brackets: { statements go here } Comments: // single line comments /* Multiple line comments cannot be nested one inside another. */

    5. Data and Objects All information in JavaScript is associated with a data type, either explicitly or implicitly. Each data type is stored differently and each is associated with a specific set of allowed operations. Variables serve as data "containers." Each "container" is given a symbolic name (its identifier). When done explicitly, this is called a "data declaration." JavaScript data declarations are done explicitly with the var keyword. JavaScript is a "weakly typed" language. You aren't required to do explicit variable declarations, and data types can be changed during a script, "on the fly." A JavaScript identifier reserves a place in memory for a variable, but does not dictate the type of the data. You can change not only the value of the contents whenever you want, but also the data type. That is, JavaScript will infer data type based on the contents of a variable "container." You cannot do this in languages such as Fortran and C!! JavaScript supports three basic data types ("primitives") numbers, strings of characters, and boolean (true or false). JavaScript variable names are always case-sensitive.

    6. Literals In the statements name="Professor Wonderful"; and pi=3.14; the values on the right are literals a string literal in the first case and a numeric literal in the second. You should avoid using literals in your code. It is better to assign literal values to a variable with an identifier.

    7. Objects and Methods In plain language, an "object" is a "thing" that has properties and can do things. A ball is an object. It has a size and a color. It can roll and bounce, etc. Languages such as JavaScript have "objects." These objects have properties (document.lastModifed) and methods document.write() ) that define what can be done by and to them.

    8. The prompt() and alert() Methods We will use these two methods for now to minimize interactions with HTML.

    9. Some String Methods (just a few)

    10. JavaScript's Operators

    11. The JavaScript Assignment Operator The JavaScript assignment operator is the "equals" sign (=). The assignment operator is NOT the same as the "equality" sign from mathematics. The meaning of the assignment operator is: Evaluate the expression on the right side of the assignment operator and assign the result to the identifier on the left side of the assignment operator. In algebra, x=a+b and a+b=x are equivalent. In JavaScript, only x=a+b; is allowed. In algebra, x=x+1 makes no sense at all, but in JavaScript, x=x+1; is a perfectly reasonable statement. Only an identifier can appear on the left side of the assignment operator in a JavaScript statement.

    12. Shorthand Arithmetic/Assignment Operators

    13. The Math Object Properties

    14. The Math Object Methods

    15. Some Details

    16. Using the Math Object

    17. Relational and Logical Opera tors

    18. if then else Constructs

    19. Using an if Statement

    20. Potential Problems with if Statement

    21. The switch() Construct

More Related