>
Greater than<
Less than>=
Greater than equal to<=
Less than equal to===
Equal to!==
Not equal to
JavaScript has three: and &&
, or ||
, and not !
.
Modulo
Modulo is the same as remainder. When % is placed between two numbers, the computer will divide the first number by the second, and then return the remainder of that division.
A function takes in inputs, does something with them, and produces an output.
Function syntax is as follows
1var functionName = function (parameter) { };
Global = variable made outside a function, Local = variable made inside a function.
Variables defined outside a function are accessible anywhere once they have been declared. They are called global variables and their scope is global.
1var globalVar = "hello";
2
3var foo = function() {
4 console.log(globalVar); // prints "hello"
5}
The variable globalVar can be accessed anywhere, even inside the function foo.
Variables defined inside a function are local variables. They cannot be accessed outside of that function.
For example:
1var bar = function() {
2 var localVar = "howdy";
3}
4console.log(localVar); // error
The variable localVar
only exists inside the function bar
. Trying to print localVar
outside the function gives a error.
Null means the value is null.
Undefined means the value isn’t defined. Undefined is given when the variable is mentioned but the value isn’t defined. If the variable wasn’t metioned it would give a ‘ReferenceError: variable is not defined.’
NaN means not a number.
i = i + 1
means we have incremented (increased) the variable i
by 1 each time.
A successful request to the server results in a response, which is the message the server sends back to you, the client.
The response from the server will contain a three-digit status code. These codes can start with a 1, 2, 3, 4, or 5, and each set of codes means something different. (You can read the full list here). They work like this:
1xx: You won’t see these a lot. The server is saying, “Got it! I’m working on your request.”
2xx: These mean “okay!” The server sends these when it’s successfully responding to your request. (Remember when you got a “200” back from Codecademy?)
3xx: These mean “I can do what you want, but I have to do something else first.” You might see this if a website has changed addresses and you’re using the old one; the server might have to reroute the request before it can get you the resource you asked for.
4xx: These mean you probably made a mistake. The most famous is “404,” meaning “file not found”: you asked for a resource or web page that doesn’t exist.
5xx: These mean the server goofed up and can’t successfully respond to your request.
In situations where you don’t know in advance when to stop looping, we can use a while loop.
turns text to all capps and all lower case respectively.
.length tells the length of the string
indexOf(‘string’) tells what is the index (starting point) of the given string
charAt(8) tells the character at index 8. since it is zero based it’ll tell you the letter at the ninth place.
.substr(start, length) gets a sub-string, or gets part of a string out based on the index given.
!
means none or not.parseInt
will convert a string to an integer. parsefloat
will give a decimal (floating) value. There is also parsebool
.1
to mean true
and 0
to mean false
.var mix = [42, true, "towel"];
var twoDimensional = [[1, 1], [1, 1]];
1var myObject = {
2key: value,
3key: value,
4key: value
5};