JavaScript. Properties and functions
In this tutorial we will discuss functions and properties. While writing code you often need to do a lot of repetitive operations. This operations are better to write into special blocks – functions.
Function is subprogramm which works with any data and returns any result. Function often needs some secondary data – parameters. Besides, function has got a name (it is recommended, functions name tell developers, what it does) and function body – code. For example:
Code lesson (js)
function function_name (argument) {
// body...
}
All languages has got its own functions. But always developers need to write their custom functions, because language functions can’t satisfy developer with him tasks.
Code lesson (js)
var str = "Я люблю javaScript";
console.log(str.length);
//charAt()
var symb = str.charAt(0);
console.log(symb);
str = str.toUpperCase();
console.log(str);
function summa(a,b) {
var s = a + b;
return s;
}
var res = summa(5,10);
console.log(res);
function division(a,b) {
if(b == 0) {
alert("На нуль делить нельзя");
return false;
}
var d = a/b;
return d;
}
var div = division(10,5);
console.log(div);
0 Comments