Introduction to Javascript Flashcards
Javascript runs…
on the browser rather than the server. Whereas before in order to perform action, data and operations were being sent to the server.
Javascript is an _____ programming language
interpreted
Javascript Alerts
alert(“Text to Display Alert”);
JS Data Types
Different Types
String
Boolean
Number
typeof()
Output of function
“number”
“boolean”
“string”
JS Variables
prompt(“Dialogue to display for prompt”);
To declare a variable use, var.
var, variables can later be changed to a different value
Example:
var myName = “Anand”;
Naming and Naming Conventions for JS Variables
Variable names cannot start with a number
Variable can only contain numbers, letters, $, and/or _
Variables follow a camel-case format.
First word contains lowercase, then subsequent words contain capital letters for their names
String Concatenation
Can combine strings using +
Example:
“Hello” + “World” -> “HelloWorld”
String Lengths and Retrieving the Number of Characters
To check the number of characters in a string
stringVariable.length
Slicing and Extracting Parts of a String
Slice Function stringslice(x, y); Slices the string from x to y. Including x, up to but not including y Example: “Anand”.slice(0,3); “Ana”
Changing Casing in Text
toUpperCase() Example: “word”.toUpperCase() “WORD” toLowerCase()
Basic Arithmetic and the Modulo Operator in Javascript
Modulo % Gives the remainder of a division Example: 9 % 6 = 3
Increment and Decrement Expressions
x++
x = x + 1;
x- -
x = x - 1;
Creating and Calling Functions
Declaring functions: function myFunction() { <code> } Calling a function myFunction();</code>