Regarding your confusion on build in functions: All programming languages have build in functions/methods.
The main difference between build in and custom functions is that you don’t have to declare the build in functions you will only call them.
The syntax for calling a build in function is the same as if you were calling a custom function.
Build in functions also only take a certain amount of parameters. If you use the build in “alert” function it takes only one parameter which is the actual text you
wish to print.
So using custom functions is a two-step process.
Step 1 declaring the function. You do that by using the function keyword followed by parameter brackets and curly brackets for the function body (code to execute):
function myFunc(myParameter)
{
alert (myParameter);
//some other code to execute can be placed here
}
(Note that we have a build in function inside our custum function)
Step 2 caling the function (usually from an event or after a series of commands.)
In this example we are calling the function from the window.onload event and passing a parameter (the text-string)
window.onload = myFunc('window has loaded');
We can reuse the function as much as we want from other events and we can pass other values to the parameters (in this example from a resize event)
window.onresize = myFunc('the window is resized');
Edit: In the example here we might as well just call the build in alert function with the same paremeter as the result would be the same but a custum fuction can be very handy for more advanced stuf like having comparison operators:
function myAdvancedFunc(myParameter, myOtherParameter)
{
if (myOtherParameter == 100)
{
alert (myParameter);
}
}
And call it like this
window.onload = myFunc('window has loaded', 100);