This is a draft cheat sheet. It is a work in progress and is not finished yet.
What is Javascript?:
A scripting language
Used to implement logic into web and mobile apps
Syntax similar to C++ |
Data Types:
- Boolean
- Null
- Undefined
- Number
- String
- Symbol |
Use the ‘Var’ keyword to declare
var x = 10;
Data type depends on what value is assigned to it
Use typeof(variable name);
to output the data type
Variables Declaration
var x;
- undefined
var x = 10;
- number
x = "Hello World";
- string |
Text Output
console.log(“Hello World”);
- outputs text to the console
console.log(“Hello World” + someVariable + “and Goodbye”);
- can concentrate output with the ‘+’ operator |
|
|
If Statements
if (x < 10)
{
console.log(“Less than 10”);
}
else
{
console.log(‘Not less than 10”);
}
|
Switch Statements
switch(x)
{
case 4:
console.log(“Hello”);
break;
case 5:
console.log(“Goodbye”);
break;
case 6:
console.log(someVariable);
break;
default:
console.log(“No Instruction”);
}
|
For Loop
for (i = 0; i < 10; i++)
{
console.log(“Number “ + i);
}
|
While Loop
while (i < 10)
{
console.log(“Number “ + i );
i++;
}
|
|
|
Do-While Loop
do
{
console.log(“Number “ + i );
i++;
}
while (i < 10);
|
Strings
var myString = “Hello World”;
console.log(myString.length); -
‘length’ operator gets length of string |
Functions
function functionName (arguments);
function Multiplier (v1, v2)
{
console.output (v1 * v2);
}
No return type |
Arrays
Javascript arrays can contain a mix of different data types
Can access and assign values to elements that in the array yet
var oscillators [“sine”, “saw’, “square”];
|
|