JavaScript (short)
Wednesday, 31 January 2024 11:47
Modern programming language that is derived from the syntax of C
It makes up the core user experience of the web
To open - Open a file with .js file extension
Unlike python, JavaScript runs client side, on your own machine when u
visit a website
TO
VARIABLES
- Similar to python variables
- No type specifier
- When a local variable is delcared it should be prefixed with var
Conditionals
if
else if
Else
Switch
?:
if
else if
Else
Switch
?:
Loops -
While
Do-while
For
Functions -
Introduced with the function keyword
Function - functionname - parameters
They can be anonymous, they don’t need a name
Arrays -
Var nums = [1, 2, 3, 4, 5];
You can mix types together as well
E.g var mixed = [1, true, 3.33, five];
Objects -
- Behave as an object oriented programming language
- Object is like a structure in C, which we might call properties
However the properties, year and model cannot stand on their own without
However the properties, year and model cannot stand on their own without
the car structure.
Objects, have properties but also methods,
Methods are like functions that are inherent to the object, and mean nothing
outside it.
- Methods cannot stand on their own
- Only existing i
- n the context of the object
NOT OBJECT ORIENTED
THIS IS OBJECT OREIENTED, the object is the core
LOOPS -
New LOOPS - iterating across key value pairs, keys or
values or all elements
For ( var key in object)
LOOPS -
New LOOPS - iterating across key value pairs, keys or
values or all elements
For ( var key in object)
{
use object[key] here
} #iterates across every key
Iterate across every value -
For (var key of object)
{
use key in here
}
Arrays are a special case of an object - therefore has numerous methods that can be
applied to them
object.map() - can be used to apply a function to all the elements of an array
Events -
Events -