150 likes | 300 Views
JavaScript. By: Daniel Moulton & Terrell Shelton. What are we looking at. JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight programming language JavaScript is usually embedded directly into HTML pages
E N D
JavaScript By: Daniel Moulton & Terrell Shelton
What are we looking at • JavaScript was designed to add interactivity to HTML pages • JavaScript is a scripting language • A scripting language is a lightweight programming language • JavaScript is usually embedded directly into HTML pages • Separate .js files can be referenced from an HTML page • JavaScript is an interpreted language (means that scripts execute without preliminary compilation) • Everyone can use JavaScript without purchasing a license
History • Originally developed in Netscape by Brendon Eich to compete with Microsoft. • Originally named Mocha LiveScript, it was later renamed JavaScript, confusing many into thinking it was associated with Java. • Microsoft adapts JavaScript in August 1996 • In November 1996, NetScape submits JavaScript to Ecma International for consideration of becoming industry standard.
What does it do? • We use JavaScript to add interactivity to our HTML pages • Reacts to events • Basic Events • Advanced Events • Can read and write HTML elements • Can be used to validate data • Browser detection • Cookie creation
Structure • Based off of the same structure as C. • Free flow • No need for semi colons to end lines.
Binding • JavaScript uses both early and late binding • Early binding is more beneficial with larger programs. • Runtime performance is faster for early bindings.
Data abstraction • There are several features that JavaScript has when it comes to data abstraction • Object based.
Data types • It only has 3 primitive types • String • Numeric • Boolean • Types are associated with values, not variables. • ‘x’ can be defined as a number, then a string. • Duck typing • Object based.
Defining data types • There are user defined data types • Anything defined as “class” is a user defined type
Control • For loop • For-in loop • If statement • While loop • Do-while loop • switch • With • Try-catch-finally • Breaks
Quirks • Security Flaws • Cross Site Scripting (XSS) • Client side code • Allows end users to see and change filesClientside code • Browser dependent
Special Features • Vast libraries • Jquery • Relation to Java • Based off of C • Other than that, none
For-in loops for( varmyVariable in document ) { document.write( myVariable + ' = ' + document[myVariable] + '<br>' ); }
With x = Math.round( Math.LN2 + Math.E + Math.pow( y, 4 ) ); Can be replaced with: with( Math ) { x = round( LN2 + E + pow( y, 4 ) ); }
Breaks for( var x = 1; x < 5; x++ ) { var y = 1; while( y < 7 ) { y++; if( y == 5 ) { break; } document.write(y); } }