functions in js code example
Example 1: startsWith() and endsWith() functions in PHP
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
Example 2: function javascript
var x = myFunction(4, 3);
function myFunction(a, b) {
return a * b;
}
Example 3: functions in javascript
function name( parameter1 ,parameter 2,..)
{
}
Example 4: javascript function
function myFunc(theObject) {
theObject.make = 'Toyota';
}
var mycar = {make: 'Honda', model: 'Accord', year: 1998};
var x, y;
x = mycar.make;
myFunc(mycar);
y = mycar.make;
Example 5: simple javascript function
function idk() {
alert('This is an alert!')
}
idk()
Example 6: js function
function name(parameter1, parameter2, parameter3) {
}