












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Dates, Maths, Regular Expressions, Arrays, and Functions are always objects. ▷ Objects are objects. In JavaScript, all values, except primitive values, ...
Typology: Exercises
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Lecture 9 CGS 3066 Fall 2016
October 20, 2016
I (^) JavaScript numbers can be written with, or without decimals. I (^) Extra large or extra small numbers can be written with scientific (exponent) notation. I (^) All numbers are 64-bit floating point. I (^) Integers can have up to 15 digits. Floats can have up to 17 decimal digits. I (^) JavaScript interprets numeric constants as hexadecimal if they are preceded by 0x. I (^) If you want numbers printed in different bases, use the toString function.
The JavaScript Math object allows you to perform mathematical tasks on numbers. I (^) Math.round(x) returns the value of x rounded to its nearest integer. I (^) Math.pow(x,y) returns the value of x to the power of y. I (^) Math.sqrt(x) returns the square root of x I (^) Math.abs(x) returns the absolute (positive) value of x I (^) Math.random() returns a random number between 0 (inclusive), and 1 (exclusive. I (^) The Math Class has many properties like PI, E, SQRT2, LOG2E, etc. I (^) The Math class also has many other functions like sin, cos, tan, floor, ceil, log, exp, etc
JavaScript strings are used for storing and manipulating text.
Adding a backslash in fromt of a character is called “escaping” the character.
There are several special escaped characters in JavaScript. I (^) \’ - single quote I (^) \” - double quote I (^) \- backslash I (^) \n - newline I (^) \t - tab I (^) \b - backspace
I (^) An object is a software representation of a real world entity. I (^) Objects have properties (whose values identify an object) and methods that act on those properties. I (^) JavaScript variables are containers for data values. I (^) The values are written as name:value pairs (name and value separated by a colon). I (^) var car = {make:"Toyota", model:"Corolla", color:"Silver", year:2009};
I (^) JavaScript methods are the actions that can be performed on objects. I (^) A JavaScript method is a property containing a function definition. I (^) Methods can be built-in (already available in JavaScript) or user defined. I (^) You create an object method with methodName : function() { code lines } I (^) You access an object method with objectName.methodName()
In JavaScript, almost “everything” is an object. I (^) Booleans, Numbers and Strings can be objects (or primitive data treated as objects). I (^) Dates, Maths, Regular Expressions, Arrays, and Functions are always objects. I (^) Objects are objects. In JavaScript, all values, except primitive values, are objects. Primitive values are: strings, numbers, true, false, null, and undefined.
I (^) Scope refers to the set of variables, objects, and functions you have access to. I (^) JavaScript has function scope: the scope changes inside functions. I (^) Variables can be local or global. I (^) The lifetime of a JavaScript variable starts when it is declared. I (^) Local variables are deleted when the function is completed. I (^) Global variables are deleted when you close (or move away from) the page.
I (^) Variables declared within a JavaScript function, become local to the function. I (^) Local variables have local scope: They can only be accessed within the function. I (^) Since local variables are only recognized inside their functions, variables with the same name can be used in different functions. I (^) Local variables are created when a function starts, and deleted when the function is completed.
I (^) HTML events are “things” that happen to HTML elements. I (^) For example, an HTML button click, a page finishing up loading, a key press, etc. are all events. I (^) JavaScript lets you execute code when events are detected. I (^) HTML allows event handler attributes, with JavaScript code, to be added to HTML elements. I (^) Event handlers can be used to handle, and verify, user input, user actions, and browser actions. I (^) Syntax: <some-HTML-element some-event=“some JavaScript”>
Event Description onclick The user clicks an HTML element onload The browser has finished loading the page onchange An HTML element has been changed onkeydown The user pushes a keyboard key onmouseover The user moves the mouse over an HTML element ondrag The event occurs when an element is being dragged onselect The event occurs after the user selects some text onsubmit The event occurs when a form is submitted
get post All form data is visible in the Form data is not in the URL. URL Protected during transmission. The size of appended data is Size of data is potentially restricted. unlimited. Very insecure. Used primarily Quite secure. Preferred by while testing. programmers.
Data validation is the process of ensuring that computer input is clean, correct, and useful.
Typical validation tasks are: I (^) has the user filled in all required fields? I (^) has the user entered a valid date? I (^) has the user entered text in a numeric field? Validation can be defined by many different methods, and deployed in many different ways.