JavaScript Operators Operators are used to perform calculations on

Javascript operators operators are used to perform

This preview shows page 17 - 27 out of 103 pages.

Image of page 17
JavaScript Comments Much like HTML, JavaScript also has a mechanism for including comments (although much more convenient). - Used for documentation or preventing code execution - // - Single Line Comment - /* */ - Multi-line comment.
Image of page 18
Data Types In programming, we often need to express different data within a program in different ways. When working with variables and data within a program, you need to be mindful of their types. - JavaScript is a Weakly/Dynamically Typed Language - Variables don't have an explicit type associated with them until runtime - Auto Conversion of data can lead to unexpected behavior - Ex: var a = 'some string' + 5;
Image of page 19
JavaScript Types JavaScript has a variety of data types available for use: - Number - String - Boolean - Array - Object - Function - RegExps
Image of page 20
JavaScript Number Numerical data in JavaScript is represented with the Number data type. - Examples: - 1.0 - 1 - 1e-15 - 0.15 * 0.12 - You can perform mathematical operations on Number data types using the operators discussed previously - The Number type is a 64 bit Floating Point value - Floating point precision errors
Image of page 21
JavaScript String In programming, a String is a collection of text characters, normally enclosed in quotation marks. - Ex: "Hello World!" - No char data type - Can use single or double quotes to define a string - Ex: 'Hello World!' - Some characters are reserved - Ex: "The man said "Hello" to the boy" - Won't Compile - To correct it, either use single quotes, or use the \ character to escape the quotes - Ex: "I \"will\" compile!";
Image of page 22
JavaScript String To concatenate strings, you can use the + operator. - Ex: var a = "Hello " + "World!"; - You can use this to split strings onto multiple lines: - var a = "Hello " - + "World!"; - You can also use the \, but that's not recommended. - You can concatenate (join) strings using the + operator.
Image of page 23
JavaScript String Strings have a variety of methods and properties that can be used to operate on the strings. - Strings have a length property, that can be accessed to get the length of the string - Ex: console.log('Hello World'.length);
Image of page 24
JavaScript String Methods Some noteworthy String Methods (these do not modify the original string, they return new values): - someString.indexOf(str) - Check if str exists in someString - someString.substring(startIndex, endIndex) - Extract the string between the specified indices - someString.toUpper/LowerCase() - Returns a modified version of the string - someString.replace(origStr, newStr) - Replace orgString instances with newStr within someString - someString.trim() - Remove whitespace characters from the start and end of the string. - someString.split(delim) - Split the string into an array around the delim string - someString.charAt(index) - Return the character at position index
Image of page 25
JavaScript Boolean In programming, booleans are used to indicate truthiness and falsiness, normally used for conditional programming logic -
Image of page 26
Image of page 27

You've reached the end of your free preview.

Want to read all 103 pages?

  • Spring '17
  • cooper
  • css, Control flow, Closure

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture