DOC PREVIEW
DePaul IT 130 - JavaScript 2

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Javascript IIJavaScript ReviewStatementsVariablesVariable declarationData typesData TypeJavaScript TypesStringsExamplesIntegersSlide 12FloatSlide 14BooleanSlide 16Another kind of valueundefined valueExpressionsSyntax alertEvaluationExampleComplex expressionSlide 24The "+" trapOperatorsFunctionsPredefined FunctionsFunction syntaxJavascript IIExpressions andData Types2JavaScript Reviewprograms executed by the web browserprograms embedded in a web pageusing the script elementprograms consist of statementsexecuted sequentially3StatementsEnd with semi-colonCannot occupy multiple linesAssignment statementvar = value;The “value” on the right can be any legal expressionFunction calldocument.write ("foo");4VariablesA variable is a named location where a value can be storedIn JavaScriptusing a variable creates itcan also declareOther languagesrequire that variables be declared before being usedVariables have "scope"locations in the program where they are validwill discuss this later on5Variable declarationDeclaration is optional in JavascriptSyntaxvar foo;Says that foo is a variable we will use later6Data typesWhat is the difference between the following statementsval1 = "53";val2 = 53;These values are different to JavaScriptstored differentlymanipulated differentlysame operation may mean something different+ on strings in concatenation+ on numbers is addition7Data TypeA characterization of a stored valueDetermineswhat kinds of values can be storedhow the value is stored internallywhat operations can be appliedSyntactic representationhow the value is expressed in a program8JavaScript TypesStringsIntegersFloatsreal numbersBooleantrue or false9StringsWhat valueslists of charactersany length including the zero-length “null” string “”What operationsconcatenation (+ operator)output to the Web pageusing document.write(…)returned by prompt() functionSyntaxdouble or single quotes10Examplesval1 = “Hello";val2 = ‘ there';val3 = val1 + val2;document.write (val3);val4 = “45”;val2 = val3 + val5;document.write (val2);11IntegersWhat valueswhole numbers between -9223372036854775808 and 9223372036854775808What operationsstandard mathematical operations (+, -, *, /)special math functionsSyntaxunquoted integersNotebook doesn't use integers in examples12Examplesval1 = 45;val2 = 055;val3 = val1 + val2;Math.sqrt(val3);13FloatWhat valuesdecimal values from ±1.0x10308 to ± 1.0x10-32317 digits of precision (past decimal point)What operationsstandard mathematical operationsspecial math functionsSyntaxunquoted decimal valuesscientific notation1.2e3 = 1.2 x 103 = 120014Examplesval1 = 5.3;val2 = 5.3e1;val3 = val1 + val2;Math.floor(val3);15BooleanWhat valuestrue / falseWhat operationslogical operationsand &&or ||not !Syntaxkeywords (true, false)16Examplesval1 = true;val2 = false;val3 = val1 && !val2;17Another kind of value<script type="text/javascript">var foo;document.write (foo);</script>What is the value of foo?18undefined valueThis is the value of a variable when it is createdif you use a variable without defining it, you get an errorYou can declare a variable without giving it a valuenot an errorvariable has no valueunexpected results19ExpressionsAn expression is a legal combination of Javascript values, operators, function calls and variablesthat evaluates to a valueExamplesa + b5 / 63.14159 * r * rMath.sqrt (errorTerm)"foo" + "-" + "bar"20Syntax alertAn expression is not a statementan expression may be part of a statementnote: no semi-colonExample(a + b) / 2expressionsize = a + b;statement21EvaluationAn expression is evaluated when it is executed (run-time)StepsEach variable is replaced by its current valueOperators are appliedUntil a single value remains22Examplea = 5;b = 20;position = (a * 5) + (b / 10);23Complex expressionExpressions can be large and complexJavaScript doesn't careReaders of your program might careA complex expression can always be simplifiedby using intermediate variables24Examplecomplex expressionslope = ( (y1 – y2) / (x1 – x2) );simplifieddeltaY = y1 – y2;deltaX = x1 – x2;slope = deltaY / deltaX;25The "+" trap+ means different things for different types"foo" + "bar"  "foobar""5" + "6"  "56"5 + 6  11What about?"5" + 66 + "foo"26Operators+ is an operatorAn operatortakes two values (sometimes one)makes ("returns") a new valueSome operators are two characters&&Assignment is not an operation= is not an operator!27FunctionsLike an operatortakes valuesdoes some operationreturns a resultButhas a name instead of symbolcan take any number of valuescan be user-defined28Predefined FunctionsYou can define your own functionslater in the classMany built-inpromptdocument.write29Function syntaxprompt ( "Enter a number", "0")return value is a string containing the user inputNo parameters?Math.random ()there's still a list, just an empty onefunction name parameter #1parameter #2parameter


View Full Document

DePaul IT 130 - JavaScript 2

Download JavaScript 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view JavaScript 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view JavaScript 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?