Docsity

-JavaScript-The-Definitive-Guide-Notes-Pt, Guías, Proyectos, Investigaciones de Programación Javascript

Toggle sidebar
bg1
JavaScript: The Definitive Guide Notes
Essentials: case-sensitive, untyped
Chapter 1, Introduction to JavaScript
JS is untyped
Objects are more like associative arrays (hashes in Perl)
JS is a misnomer; it was originally called LiveScript and isn’t related to Java,
however the language can interact well with Java applets for drawing and network
functions
Chapter 2, Lexical Structure
Lexical structure: low-level language syntax
Core JS is case-sensitive, but client-side JS has its exception with IE3
White space is ignored
Commenting:
o// for one line
o/* */ for multiple lines
Literals (a data value)
o“”, '’, 12, true, false, /javascript/cgi (reg expression), null, {}, [ ]
Identifiers (a name, typically of a variable or function)
oMay begin with a letter, _, or $
oMay not begin with a number, or be reserved keywords
Reserved words: pg. 27
Chapter 3, Data Types and Values
Objects (including functions and arrays), Numbers, Strings, Boolean, and null and
undefined (both represent a single value)
An object can be thought of as a container of other data types
Other specialized objects: Date class, RegExp class, and the Error class
Numbers are 64-bit floating-point values, according to IEEE 754
Hex values begin with 0x or 0X which leads with the digit 0
Octal literals (base-8 format) begin with a 0 followed by three digits between 0-7
Floating-point literal syntax [digits][.digits][(E|e)][(+|-)digits]
Escape characters: pg. 35
Working with Strings:
oaString.length
os.charAt(n) is the nth character in s
os.substring(a,b) is a string composed of the letters between the ath and bth
characters in string s
os.indexOf(‘a’) returns the position of the first instance of the a character in
string s
pf3
pf4

Vista previa parcial del texto

¡Descarga -JavaScript-The-Definitive-Guide-Notes-Pt y más Guías, Proyectos, Investigaciones en PDF de Programación Javascript solo en Docsity!

JavaScript: The Definitive Guide Notes

Essentials: case-sensitive, untyped Chapter 1, Introduction to JavaScript  JS is untyped  Objects are more like associative arrays (hashes in Perl)  JS is a misnomer; it was originally called LiveScript and isn’t related to Java, however the language can interact well with Java applets for drawing and network functions Chapter 2, Lexical Structure  Lexical structure: low-level language syntax  Core JS is case-sensitive, but client-side JS has its exception with IE  White space is ignored  Commenting: o // for one line o /* */ for multiple lines  Literals (a data value) o “”, '’, 12, true, false, /javascript/cgi (reg expression), null, {}, [ ]  Identifiers (a name, typically of a variable or function) o May begin with a letter, _, or $ o May not begin with a number, or be reserved keywords  Reserved words: pg. 27 Chapter 3, Data Types and Values  Objects (including functions and arrays), Numbers, Strings, Boolean, and null and undefined (both represent a single value)  An object can be thought of as a container of other data types  Other specialized objects: Date class, RegExp class, and the Error class  Numbers are 64-bit floating-point values, according to IEEE 754  Hex values begin with 0x or 0X which leads with the digit 0  Octal literals (base-8 format) begin with a 0 followed by three digits between 0-  Floating-point literal syntax [digits][.digits][(E|e)][(+|-)digits]  Escape characters: pg. 35  Working with Strings: o aString.length o s.charAt(n) is the nth character in s o s.substring(a,b) is a string composed of the letters between the ath and bth characters in string s o s.indexOf(‘a’) returns the position of the first instance of the a character in string s

o stings can sometimes be accessed like arrays, so to get the 5th^ char of string s, use s[5], but avoid this syntax because it is not supported by ECMAScript v  Unnamed functions can be embedded as literal data types using function literals, sometimes called Lambda Functions o var square = function(x) { return xx; }  You can also define functions using the function constructor: var square = new function(“x”, “return xx;”); however this technique may result in functions which are less efficient  Object literals o var point = { x:1.2, y:23.1 }; o in the example above, point.x is set to 1.  Arrays o Constructor function: array(), var a = new array(); a[0] = 5; o Literal: a = [1, “javascript”, true];  Undefined variables o var undefined;  Date object o All dates are zero based, so for example December would be month 11  RegEx o Text between //’s  Primitive Data Type Wrappers o There are three primitive data types: strings, numbers, and Booleans o The primitive types cannot be operated on like objects, so whenever they are needed to be accessed using object notation, a copy of the data is made into an object, a wrapper object, so that the data contained in the primitive can be interfaced o To create a primitive string, use var a = “this is a string”; o To create a string wrapper, use var a = new String(“this is a string”); o The distinction between a primitive and a wrapper is slight enough, and the wrapper conversion process efficient enough, that it should not be taken into consideration when developing Chapter 4, Variables  JavaScript is dynamically typed, so it changes the types of variables automatically and as needed (like when appending a number to a string, the number gets converted to a string before being appended)  Declaration: var i;  Multiple declarations: var i, sum;  JavaScript with automatically (implicitly) declare an object if “var” is not used  Implicitly declared variables are assumed to be global variables, to make a local variable for use in a single function, you must use the var declaration  Best Practice: declare all variables at the beginning of a function, because the scope of a local function is the entire function body, not just the part of the function following the declaration

o This operator works like so: Boolean value or conditional (a)? code to execute if a is true : code to execute if a is false o The operator is shorthand for a simple if/then statement Chapter 6, Statements  Use {} to make multiple statements act as a single statement where they’re expected, like in functions 