
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.

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;

JavaScript Types
JavaScript has a variety of data types available for use:
-
Number
-
String
-
Boolean
-
Array
-
Object
-
Function
-
RegExps

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

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!";

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.

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);

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

JavaScript Boolean
In programming, booleans are used to indicate truthiness and falsiness,
normally used for conditional programming logic
-


You've reached the end of your free preview.
Want to read all 103 pages?
- Spring '17
- cooper
- css, Control flow, Closure