/* Not all JavaScript statements are "executable commands". Anything after double slashes // is treated as a comment. Comments are ignored, and will not be executed: */
Слайд 17JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified with
unique names.
The general rules for constructing a names for variables (unique identifiers) are: Names must begin with a letter Names can also begin with $ and _ Names can contain letters, digits, underscores, and dollar signs. Names are case sensitive (y and Y are different variables) Can be used “camelCase” Reserved words (like JavaScript keywords) cannot be used as names
Слайд 18JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified with
unique names.
The general rules for constructing a names for variables (unique identifiers) are: Names must begin with a letter Names can also begin with $ and _ Names can contain letters, digits, underscores, and dollar signs. Names are case sensitive (y and Y are different variables) Can be used “camelCase” Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
Слайд 19JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified with
unique names.
The general rules for constructing a names for variables (unique identifiers) are: Names must begin with a letter Names can also begin with $ and _ Names can contain letters, digits, underscores, and dollar signs. Names are case sensitive (y and Y are different variables) Can be used “camelCase” Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
In JavaScript, the equal sign (=) is an "assignment" operator, is not an "equal to" operator.
x = x + 5
Слайд 20JavaScript Identifiers All JavaScript variables (and JavaScript functions) must be identified with
unique names.
The general rules for constructing a names for variables (unique identifiers) are: Names must begin with a letter Names can also begin with $ and _ Names can contain letters, digits, underscores, and dollar signs. Names are case sensitive (y and Y are different variables) Can be used “camelCase” Reserved words (like JavaScript keywords) cannot be used as names
JavaScript variables can hold many types of data.
In JavaScript, the equal sign (=) is an "assignment" operator, is not an "equal to" operator.
x = x + 5
If you put quotes around a numeric value, it will be treated as a text string.
var pi = '3.14'; var constPi=3.14;
Слайд 21Declaring (Creating) JavaScript Variables var carName; //Variable declared without a value will
have the value undefined. carName = "Volvo";
//or
var carName = "Volvo";
//For many Variables start the statement with var and separate the variables by comma: var lastName = "Doe", age = 30, job = "carpenter";
//or
var lastName = "Doe"; var age = 30; var job = "carpenter";
Слайд 22Global variables are evil!!!! evil = 'Variable declaration without var'
// Number assigned by a number literal var songs = albums * 10; // Number assigned by an expression literal var title = "Highway to Hell"; // String assigned by a string literal var members = [ "Angus Young", "Phil Rudd", "Cliff Williams", "Brian Johnson", "Stevie Young" ]; // Array assigned by an array literal var band = {name:"AC/DC", startYear:1973}; // Object assigned by an object literal
Слайд 41String Methods Finding a String in a String:
indexOf()
var str = "The
indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string"; var pos = str.indexOf("index");
Слайд 42String Methods Finding a String in a String:
indexOf()
var str = "The
indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string"; var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string"; var pos = str.lastIndexOf("index");
Слайд 43String Methods Finding a String in a String:
indexOf()
var str = "The
indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string"; var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string"; var pos = str.lastIndexOf("index"); Return -1 if the text is not found! JavaScript counts positions from zero. Both methods accept a second parameter as the starting position for the search.
Слайд 44String Methods Finding a String in a String:
indexOf()
var str = "The
indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string"; var pos = str.indexOf("index");
lastIndexOf()
var str = "The lastIndexOf() method returns the index of the last occurrence of a specified text in a string"; var pos = str.lastIndexOf("index"); Return -1 if the text is not found! JavaScript counts positions from zero. Both methods accept a second parameter as the starting position for the search.
search() var str = "The search() can work with regular expressions and returns the position of the match"; var pos = str.search("search");
var text1 = "Hello World!"; var text2 = text1.toUpperCase(); var text3 = text1.toLowerCase();
Слайд 50String Methods concat(string1, string2, ..., stringX) The concat() method can be used instead
of the plus operator. var text = "Hello" + " " + "World!"; var text = "Hello".concat(" ","World!");
Converting a String to an Array: split(reg|substr) var txt = "a,b,c,d,e"; // String txt.split(","); // Split on commas var txt = "a bb c d e"; // String txt.split(" "); // Split on spaces var txt = "a|b|c|d|e"; // String txt.split("|"); // Split on pipe
Слайд 51Numbers By default, Javascript displays numbers as base 10 decimals. Base 16 (hex),
Слайд 59Number methods toString() var x = 123; x.toString(); //
returns 123 from variable x (123).toString(); // returns 123 from literal 123 (100 + 23).toString(); // returns 123 from expression 100 + 23
Слайд 60Number methods toString() var x = 123; x.toString(); //
returns 123 from variable x (123).toString(); // returns 123 from literal 123 (100 + 23).toString(); // returns 123 from expression 100 + 23
toFixed(precision) returns a string, with the number written with a specified number of decimals var x = 9.656; x.toFixed(0); // returns 10 x.toFixed(2); // returns 9.66 x.toFixed(4); // returns 9.6560
Слайд 61Number methods toString() var x = 123; x.toString(); //
returns 123 from variable x (123).toString(); // returns 123 from literal 123 (100 + 23).toString(); // returns 123 from expression 100 + 23
toFixed(precision) returns a string, with the number written with a specified number of decimals var x = 9.656; x.toFixed(0); // returns 10 x.toFixed(2); // returns 9.66 x.toFixed(4); // returns 9.6560
toPrecision(precision) returns a string, with a number written with a specified length var x = 9.656; x.toPrecision(); // returns 9.656 x.toPrecision(2); // returns 9.7 x.toPrecision(4); // returns 9.656
Слайд 62Booleans Everything With a Real Value is True:
Слайд 64Arrays JavaScript arrays are used to store multiple values in a single
variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"]; var cars = new Array("Saab", "Volvo", "BMW");
Слайд 65Arrays JavaScript arrays are used to store multiple values in a single
variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"]; var cars = new Array("Saab", "Volvo", "BMW");
Access the Elements of an Array:
var name = cars[0]; cars[0] = "Opel";
[0] is the first element in an array. [1] is the second. Array indexes start with 0. In JavaScript, arrays use numbered indexes.
Слайд 66Arrays JavaScript arrays are used to store multiple values in a single
variable.
var array-name = [item1, item2, ...];
var cars = ["Saab", "Volvo", "BMW"]; var cars = new Array("Saab", "Volvo", "BMW");
Access the Elements of an Array:
var name = cars[0]; cars[0] = "Opel";
[0] is the first element in an array. [1] is the second. Array indexes start with 0. In JavaScript, arrays use numbered indexes.
Looping Array Elements var index, text=""; var fruits = ["Banana", "Orange", "Apple", "Mango"]; for (index = 0; index < fruits.length; index++) { text += fruits[index]; } console.log(text);
var fruits = ["Banana", "Orange","Apple", "Mango"];
splice(index[, deleteCount,
elem1, ..., elemN])
fruits.splice(2, 0, "Lemon", "Kiwi");
The first parameter (2) defines the position where new elements should be added (spliced in). The second parameter (0) defines how many elements should be removed. The rest of the parameters ("Lemon" , "Kiwi") define the new elements to be added.
Слайд 78Array Methods var fruits = ["Banana", "Orange","Apple", "Mango"];
Если не удалось найти и скачать презентацию, Вы можете заказать его на нашем сайте. Мы постараемся найти нужный Вам материал и отправим по электронной почте. Не стесняйтесь обращаться к нам, если у вас возникли вопросы или пожелания:
Это сайт презентаций, докладов, проектов, шаблонов в формате PowerPoint. Мы помогаем школьникам, студентам, учителям, преподавателям хранить и обмениваться учебными материалами с другими пользователями.