Lecture05-JS_Basics.pdf - Making web pages interactive •...

This preview shows 1 out of 9 pages.

Making web pages interactive In this lecture we will learn about JavaScript, language that is used to make our web pages interactive. It is default scripting language to all modern browsers. As we learn, we find JavaScript syntax to be similar to languages we already know like C and Java, but it behaves drastically different in some cases, which makes JavaScript the most misunderstood programming language. Science of consciousness: As our consciousness grows, we become able to make discriminations between things that look similar on the surface level.
Image of page 1

Subscribe to view the full document.

What is JavaScript? A lightweight programming language ("scripting language") Used to make web pages interactive React to events (ex: page load, user clicks, timer events, ajax events) Perform DOM manipulations (style, value, structure) Perform client side validations Perform calculations (execute business logics) on browser A web standard (but not supported identically by all browsers ) NOT related to Java other than by name and some syntactic similarities Java was most popular language at time it was developed international specification: ECMAScript
Image of page 2
JavaScript vs. Java Interpreted , not compiled More relaxed syntax and rules Fewer and "looser" data types Variables don't need to be declared Errors often silent (few exceptions) Key construct is the function rather than the class "First-Class" functions are used in many situations Functional programming language, if used properly OO language that does not have classes Contained within a web page and integrates with its HTML/CSS content Powerful and lightweight Many pitfalls Alert! JavaScript: The Good Parts
Image of page 3

Subscribe to view the full document.

First JavaScript Statement: alert alert("message"); a JS command that pops up a dialog box with a message e.g. alert("Hello, world!");
Image of page 4
Variables and types Variables are declared with the var keyword (case sensitive) Types are not specified, but JS does have types ("loosely typed") can find out a variable's type by calling typeof(variable_name) ; var name = expression; var age = 32 ; var weight = 127.4 ; var clientName = "Connie Client" ;
Image of page 5

Subscribe to view the full document.

Primitive types Primitive type : is a type that’s represented as a single value (not object) undefined null boolean : truthy or falsy number : float, int string (with single or double quotation) symbol (ES6) immutable type for objects (object wrapper) Types are dynamic and JS Engine will automatically change between types or wrap a primitive type when needed (coercion) var a = 1 + '2' // '12' concatenation in JS with +
Image of page 6