Summary - CGS3066: Web Programming and Design Summer 2014
. high-level, dynamic, untyped, and interpreted programming language ... is prototype-based with first-class functions, … ... supporting object-oriented, imperative, and functional programming ... has an API for working with text, arrays, dates and regular expressions ● Not particularly similar to Java: More like C crossed with Self/Scheme ○ C-like statements with everything objects, closures, garbage collection, etc. ● Also known as ECMAScript 2 CS142 Lecture Notes - JavaScript Basics Some thoughts about JavaScript ● Example of a scripting language ○ Interpreted, less declaring of things, just use them (popular today: e.g. python) ● Seems like it was designed in a rush ○ Some “Good Parts”, some not so good ○ Got a bad reputation ● Many programmers use a subset that avoids some common problems ● "use strict"; tweaks language to avoid some problematic parts ● Language being extended to enhance things: New ECMAScript every year! ○ Transpiling common so new features used: e.g ECMAScript Version N, TypeScript ● Code quality checkers (e.g. jslint, jshint, eslint) widely used 3 CS142 Lecture Notes - JavaScript Basics Good news if you know C - JavaScript is similar i = 3; i = i * 10 + 3 + (i / 10); while (i = 0) { sum += i*i; // Comment i--; } for (i = 0; i 10; i++) { } /* this is a comment */ 4 if (i 3) { i = foobar(i); } else { i = i * .02; } Most C operators work: * / % + - ! = = && || ?: function foobar(i) { return i;} continue/break/return CS142 Lecture Notes - JavaScript Basics JavaScript has dynamic typing var i; // Need to define variable ('use strict';), note: untyped typeof i == 'undefined' // It does have a type of ‘undefined’ i = 32; // Now: typeof i == typeof 32 == 'number' i = "foobar"; // Now: typeof i == typeof 'foobar' == 'string' i = true; // Now typeof i == 'boolean' ● Variables have the type of the last thing assigned to it ● Primitive types: undefined, number, string, boolean, function, object 5 CS142 Lecture Notes - JavaScript Basics Variable scoping with var: Lexical/static scoping Two scopes: Global and function local var globalVar; function foo() { var localVar; if (globalVar 0) { var localVar2 = 2; } // localVar2 is valid here } 6 All var statements
Written for
- Institution
- CGS3066: Web Programming and Design Summer 2014
- Course
- CGS3066: Web Programming and Design Summer 2014
Document information
- Uploaded on
- July 8, 2024
- Number of pages
- 24
- Written in
- 2023/2024
- Type
- SUMMARY
Subjects
-
javascript basics mendel rosenblum3