JavaScript/Glossary
Appearance
We try to keep consistency within the Wikibook when using technical terms. Therefore here is a short glossary.
object | An object is an associative array with key-value pairs. The pairs are called properties. All data types are derived from object - with the exception of primitive data types. |
property | A key-value pair that is part of an object. The key part is a string or a symbol, the value part is a value of any type. |
dot notation | The syntax to identify a property of an object using a dot: myObject.propertyKey
|
bracket notation | The syntax to identify a property of an object using brackets: myObject["propertyKey"]
|
curly braces notation | The syntax to express an object 'literaly' using { }: const myObject = {age: 39}
|
function | A function is a block of code introduced by the keyword function , an optional name, open parenthesis, optional parameters, and closing parenthesis.
function greeting(person) {
return "Hello " + person;
};
The above function is a named function. If you omit the function name, we call it a anonymous function. In this case, there is an alternative syntax by using the arrow syntax =>. function (person) { // no function name
return "Hello " + person;
};
// 'arrow' syntax. Here is only the definition of the function.
// It is not called, hence not running.
(person) => {
return "Hello " + person;
};
// or:
(person) => {return "Hello " + person};
// assign the definition to a variable to be able to call it.
let x = (person) => {return "Hello " + person};
// ... and execute the anonymous function by calling the variable
// that points to it: x(...)
alert( x("Mike") );
// interesting:
alert(x);
// execute an anonymous function directly
((person) => {
alert("Hello " + person);
})("Mike");
|
method | A method is a function stored as a key-value pair of an object. The key represents the method name, and the value the method body. A method can be defined and accessed with the following syntax:
let person = {
firstName: "Tarek",
city : "Kairo",
show : function() {
return this.firstName +
" lives in " +
this.city;
},
};
alert(person.show());
|
callback function | A function that is passed as an argument to another function. |
console | Every browser contains a window where internal information is shown. It's called the console and normally not opened. In most browsers, you can open the console via the function key F12 .
|
item | A single value in an array. Same as 'element'. |
element | A single value in an array. Same as 'item'. |
parameter | When defining a function, variables can be declared in its signature, e.g.,: function f(param1, param2) . Those variables are called parameters.
|
argument | When calling a function, variables can be stated to be processed in the function, e.g.,: f(arg1, arg2) . Those variables are called arguments. The arguments replace the parameters which were used during the function definition.
|