From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- files/el/web/javascript/index.html | 112 ++++ .../web/javascript/reference/functions/index.html | 596 +++++++++++++++++++++ .../index.html" | 221 ++++++++ .../javascript/reference/global_objects/index.html | 193 +++++++ files/el/web/javascript/reference/index.html | 51 ++ .../reference/operators/comma_operator/index.html | 154 ++++++ .../web/javascript/reference/operators/index.html | 301 +++++++++++ 7 files changed, 1628 insertions(+) create mode 100644 files/el/web/javascript/index.html create mode 100644 files/el/web/javascript/reference/functions/index.html create mode 100644 "files/el/web/javascript/reference/functions/\317\200\317\201\316\277\316\265\317\200\316\271\316\273\316\265\316\263\316\274\316\255\316\275\316\265\317\202_\317\200\316\261\317\201\316\254\316\274\316\265\317\204\317\201\316\277\316\271/index.html" create mode 100644 files/el/web/javascript/reference/global_objects/index.html create mode 100644 files/el/web/javascript/reference/index.html create mode 100644 files/el/web/javascript/reference/operators/comma_operator/index.html create mode 100644 files/el/web/javascript/reference/operators/index.html (limited to 'files/el/web/javascript') diff --git a/files/el/web/javascript/index.html b/files/el/web/javascript/index.html new file mode 100644 index 0000000000..fbe8c790b4 --- /dev/null +++ b/files/el/web/javascript/index.html @@ -0,0 +1,112 @@ +--- +title: JavaScript +slug: Web/JavaScript +translation_of: Web/JavaScript +--- +
{{JsSidebar}}
+ +

Η JavaScript® (συντομογραφία JS) είναι μια αντικειμενοστρεφής, ελαφριά γλώσσα προγραμματισμού που δεν χρειάζεται μεταγλώτισση (compailation), με πρώτης κατηγορίας λειτουργίες. Ενώ είναι κυρίως γνωστή ως γλώσσα σενάριου (scripting language) για ιστοσελίδες, ωστόσο χρησιμοποιείται σε πολλά περιβάλλοντα χωρίς την χρήση προγράμματος περιήγησης (browser) όπως node.js ή Apache CouchDB. Πρόκειται για μια πρωτότυπη , πολλαπλών παραδείγματων scripting γλώσσα προγραμματισμού που είναι δυναμική, και υποστηρίζει αντικειμενοστρεφή, επιβλητικό, και λειτουργικό στυλ του προγραμματισμού. Διαβάστε περισσότερα σχετικά με την JavaScript.

+ +

Αυτό το τμήμα της ιστοσελίδας είναι αφιερωμένο στην ίδια τη γλώσσα JavaScript, και όχι στα μέρη που δεν είναι ειδικά για ιστοσελίδες ή άλλα περιβάλλοντα υποδοχής. Για πληροφορίες σχετικά με {{Glossary("API","APIs")}} ειδικά για ιστοσελίδες, παρακαλούμε δείτε τα Web APIs και DOM.

+ +

Το πρότυπο της  JavaScript ονομάζεται ECMAScript. Από το 2012, όλοι τα σύγχρονα προγράμματα περιήγησης (browsers) υποστηρίζουν πλήρως την ECMAScript 5.1. Παλαιότεροι φυλλομετρητές υποστηρίζουν τουλάχιστον την ECMAScript 3. Στις 17 Ιουνίου του 2015, δημοσιεύθηκε η 6η κύρια έκδοση της ECMAScript. Επίσημα η έκδοση αυτή ονομάζεται ECMAScript 2015, αλλά συχνά αναφέρεται και ως ECMAScript 6 ή ES6. Το εγχειρίδιο που παρουσιάζεται καλύπτει την ECMAScript 6 ενώ έχει ήδη ξεκινήσει η διαδικασία με τα πρώτα τμήματα της ECMAScript 7.

+ +

Δεν πρέπει να μπερδεύουμε την JavaScript με την Java programming language. Η Java είναι εμπορικά κατοχυρωμένη από την Oracle στις Η.Π.Α. και σε άλλες χώρες.  Ωστόσο οι δύο αυτές γλώσσες προγραμματισμού έχουν διαφορετική σύνταξη, φρασεολογία και χρήσεις.

+ +
+
+

ΜΑΘΗΜΑΤΑ

+ +

Μάθε πως να προγραμματίζεις με την JavaScript με οδηγίες και μαθήματα.

+ +

Για αρχάριους

+ +

Περιηγηθείτε στην ενότητα Περιοχή μαθημάτων της Javascript αν θέλετε να μάθετε Javascript αλλά δεν έχετε προηγούμενη εμπειρία. Οι πλήρεις ενότητες που παρέχονται είναι οι εξής :

+ +
+
JavaScript τα πρώτα βήματα
+
Απαντά σε ορισμένα θεμελιώδη ερωτήματα όπως τι είναι το JavaScript, με τι μοιάζει, και τι μπορεί να κάνει καθώς και τα βασικά χαρακτηριστικά της Javascript όπως μεταβλητές, συμβολοσειρές, αριθμούς και πίνακες.
+
Δομικά στοιχεία της JavaScript
+
Συνεχίζει την κάλυψη των βασικών θεμελιωδών χαρακτηριστικών της Javascript στρέφοντας την προσοχή μας σε κοινούς τύπους κομματιών κώδικα, όπως οι δηλώσεις συνθήκης (conditional statements), βρόγχους (loops), λειτουργίες (functions) και γεγονότα (events).
+
Παρουσίαση αντικειμένων (objects) της JavaScript
+
Είναι πολύ σημαντικό να κατανοήσετε την αντικειμενοστραφή (object-oriented) φύση της JavaScript, αν θέλετε να προχωρήσετε περισσότερο με τις γνώσεις σας στη γλώσσα και να γράφετε πιο αποδοτικό κώδικα, γι' αυτό παρέχεται αυτή την ενότητα για να σας βοηθήσει.
+
+ +

Οδηγός Javascript

+ +
+
Οδηγός Javascript
+
Ένας αναλυτικότερος οδηγός για την Javascript για εκείνους που έχουν προηγούμενη εμπειρία είτε στην Javascript είτε σε κάποια άλλη γλώσσα προγραματισμού.
+
+ +

Μεσαίο επίπεδο

+ +
    +
  • αυστηρή ισότητα χρησιμοποιώντας ===
  • +
  •  χαλαρή ισότητα χρησιμοποιώντας ==
  • +
  • την μέθοδο Object.is()
  • +
+ +
+
Εισαγωγή ξανά στην JavaScript
+
Επισκόπηση για εκείνους που νομίζουν ότι γνωρίζουν σχετικά με την Javascript.
+
Δόμες δεδομένων της JavaScript
+
Επισκόπηση των διαθέσιμων δομών δεδομένων στην JavaScript.
+
Συγκρίσεις ισότητας και ομοιότητας
+
Η Javascript προσφέρει τρεις διαφορετικές λειτουργίες σύγκρισης αξίας : 
+
+ +

Για προχωρημένους

+ +
+
Κληρονομικότητα και η αλυσίδα των πρωτότυπων
+
Επεξήγηση της ευρέως παρεξηγημένης και υποτιμημένης κληρονομικότητας που βασίζεται στα πρωτότυπα.
+
Αυστηρή λειτουργία
+
Η αυστηρή λειτουργία ορίζει ότι δεν μπορείτε να χρησιμοποιήσετε οποιαδήποτε μεταβλητή πριν την αρχικοποίηση της. Πρόκειται για μια περιορισμένη παραλλαγή του ECMAScript 5 για την ταχύτερη απόδοση και τον ευκολότερο εντοπισμό σφαλμάτων.
+
JavaScript typed arrays
+
JavaScript typed arrays provide a mechanism for accessing raw binary data.
+
Διαχείρηση Μνήμης
+
Κύκλος ζωής μνήμης και συλλογή απορριμάτων στην JavaScript.
+
Μοντέλο συγχρονισμού και Βρόγχος Γεγονότων.
+
Η JavaScript έχει ένα μοντέλο συγχρονισμού βασισμένο σε έναν "βρόγχο (Λούπα) γεγονότος".
+
+
+ +
+

Reference

+ +

Browse the complete JavaScript reference documentation.

+ +
+
Standard objects
+
Εξοικιωθείτε με τα standard built-in αντικείμενα {{jsxref("Array")}}, {{jsxref("Boolean")}}, {{jsxref("Date")}}, {{jsxref("Error")}}, {{jsxref("Function")}}, {{jsxref("JSON")}}, {{jsxref("Math")}}, {{jsxref("Number")}}, {{jsxref("Object")}}, {{jsxref("RegExp")}}, {{jsxref("String")}}, {{jsxref("Map")}}, {{jsxref("Set")}}, {{jsxref("WeakMap")}} , {{jsxref("WeakSet")}}, και άλλα.
+
Expressions and operators
+
Learn more about the behavior of JavaScript's operators {{jsxref("Operators/instanceof", "instanceof")}}, {{jsxref("Operators/typeof", "typeof")}}, {{jsxref("Operators/new", "new")}}, {{jsxref("Operators/this", "this")}}, the operator precedence, and more.
+
Statements and declarations
+
Learn how {{jsxref("Statements/do...while", "do-while")}}, {{jsxref("Statements/for...in", "for-in")}}, {{jsxref("Statements/for...of", "for-of")}}, {{jsxref("Statements/try...catch", "try-catch")}}, {{jsxref("Statements/let", "let")}}, {{jsxref("Statements/var", "var")}}, {{jsxref("Statements/const", "const")}}, {{jsxref("Statements/if...else", "if-else")}}, {{jsxref("Statements/switch", "switch")}}, and more JavaScript statements and keywords work.
+
Functions
+
Learn how to work with JavaScript's functions to develop your applications.
+
+ +

Tools & resources

+ +

Helpful tools while writing and debugging your JavaScript code.

+ +
+
Firefox Developer Tools
+
Scratchpad, Web Console, JavaScript Profiler, Debugger, and more.
+
Firebug
+
Edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
+
JavaScript Shells
+
A JavaScript shell allows you to quickly test snippets of JavaScript code.
+
TogetherJS
+
+

Collaboration made easy.

+
+
Stack Overflow
+
Stack Overflow questions tagged with "JavaScript".
+
JavaScript versions and release notes
+
Browse JavaScript's feature history and implementation status.
+
+
+
diff --git a/files/el/web/javascript/reference/functions/index.html b/files/el/web/javascript/reference/functions/index.html new file mode 100644 index 0000000000..a18367e482 --- /dev/null +++ b/files/el/web/javascript/reference/functions/index.html @@ -0,0 +1,596 @@ +--- +title: Functions +slug: Web/JavaScript/Reference/Functions +tags: + - Constructor + - Function + - Functions + - JavaScript + - NeedsTranslation + - Parameter + - TopicStub + - parameters +translation_of: Web/JavaScript/Reference/Functions +--- +
{{jsSidebar("Functions")}}
+ +

Generally speaking, a function is a "subprogram" that can be called by code external (or internal in the case of recursion) to the function. Like the program itself, a function is composed of a sequence of statements called the function body. Values can be passed to a function, and the function will return a value.

+ +

In JavaScript, functions are first-class objects, because they can have properties and methods just like any other object. What distinguishes them from other objects is that functions can be called. In brief, they are Function objects.

+ +

For more examples and explanations, see also the JavaScript guide about functions.

+ +

Description

+ +

Every function in JavaScript is a Function object. See {{jsxref("Function")}} for information on properties and methods of Function objects.

+ +

To return a value other than the default, a function must have a return statement that specifies the value to return. A function without a return statement will return a default value. In the case of a constructor called with the new keyword, the default value is the value of its this parameter. For all other functions, the default return value is {{jsxref("undefined")}}.

+ +

The parameters of a function call are the function's arguments. Arguments are passed to functions by value. If the function changes the value of an argument, this change is not reflected globally or in the calling function. However, object references are values, too, and they are special: if the function changes the referred object's properties, that change is visible outside the function, as shown in the following example:

+ +
/* Declare the function 'myFunc' */
+function myFunc(theObject) {
+  theObject.brand = "Toyota";
+}
+
+/*
+ * Declare variable 'mycar';
+ * create and initialize a new Object;
+ * assign reference to it to 'mycar'
+ */
+var mycar = {
+  brand: "Honda",
+  model: "Accord",
+  year: 1998
+};
+
+/* Logs 'Honda' */
+console.log(mycar.brand);
+
+/* Pass object reference to the function */
+myFunc(mycar);
+
+/*
+ * Logs 'Toyota' as the value of the 'brand' property
+ * of the object, as changed to by the function.
+ */
+console.log(mycar.brand);
+
+ +

The this keyword does not refer to the currently executing function, so you must refer to Function objects by name, even within the function body.

+ +

Defining functions

+ +

There are several ways to define functions:

+ +

The function declaration (function statement)

+ +

There is a special syntax for declaring functions (see function statement for details):

+ +
function name([param[, param[, ... param]]]) {
+   statements
+}
+
+ +
+
name
+
The function name.
+
+ +
+
param
+
The name of an argument to be passed to the function. A function can have up to 255 arguments.
+
+ +
+
statements
+
The statements comprising the body of the function.
+
+ +

The function expression (function expression)

+ +

A function expression is similar to and has the same syntax as a function declaration (see function expression for details). A function expression may be a part of a larger expression. One can define "named" function expressions (where the name of the expression might be used in the call stack for example) or "anonymous" function expressions. Function expressions are not hoisted onto the beginning of the scope, therefore they cannot be used before they appear in the code.

+ +
function [name]([param[, param[, ... param]]]) {
+   statements
+}
+
+ +
+
name
+
The function name. Can be omitted, in which case the function becomes known as an anonymous function.
+
+ +
+
param
+
The name of an argument to be passed to the function. A function can have up to 255 arguments.
+
statements
+
The statements comprising the body of the function.
+
+ +

Here is an example of an anonymous function expression (the name is not used):

+ +
var myFunction = function() {
+    statements
+}
+ +

It is also possible to provide a name inside the definition in order to create a named function expression:

+ +
var myFunction = function namedFunction(){
+    statements
+}
+
+ +

One of the benefits of creating a named function expression is that in case we encountered an error, the stack trace will contain the name of the function, making it easier to find the origin of the error.

+ +

As we can see, both examples do not start with the function keyword. Statements involving functions which do not start with function are function expressions.

+ +

When functions are used only once, a common pattern is an IIFE (Immediately Invokable Function Expression).

+ +
(function() {
+    statements
+})();
+ +

IIFE are function expressions that are invoked as soon as the function is declared.

+ +

The generator function declaration (function* statement)

+ +

There is a special syntax for generator function declarations (see {{jsxref('Statements/function*', 'function* statement')}} for details):

+ +
function* name([param[, param[, ... param]]]) {
+   statements
+}
+
+ +
+
name
+
The function name.
+
+ +
+
param
+
The name of an argument to be passed to the function. A function can have up to 255 arguments.
+
+ +
+
statements
+
The statements comprising the body of the function.
+
+ +

The generator function expression (function* expression)

+ +

A generator function expression is similar to and has the same syntax as a generator function declaration (see {{jsxref('Operators/function*', 'function* expression')}} for details):

+ +
function* [name]([param[, param[, ... param]]]) {
+   statements
+}
+
+ +
+
name
+
The function name. Can be omitted, in which case the function becomes known as an anonymous function.
+
+ +
+
param
+
The name of an argument to be passed to the function. A function can have up to 255 arguments.
+
statements
+
The statements comprising the body of the function.
+
+ +

The arrow function expression (=>)

+ +

An arrow function expression has a shorter syntax and lexically binds its this value (see arrow functions for details):

+ +
([param[, param]]) => {
+   statements
+}
+
+param => expression
+
+ +
+
param
+
The name of an argument. Zero arguments need to be indicated with ().  For only one argument, the parentheses are not required. (like foo => 1)
+
statements or expression
+
Multiple statements need to be enclosed in brackets. A single expression requires no brackets. The expression is also the implicit return value of the function.
+
+ +

The Function constructor

+ +
+

Note: Using the Function constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.

+
+ +

As all other objects, {{jsxref("Function")}} objects can be created using the new operator:

+ +
new Function (arg1, arg2, ... argN, functionBody)
+
+ +
+
arg1, arg2, ... argN
+
Zero or more names to be used by the function as formal parameters. Each must be a proper JavaScript identifier.
+
+ +
+
functionBody
+
A string containing the JavaScript statements comprising the function body.
+
+ +

Invoking the Function constructor as a function (without using the new operator) has the same effect as invoking it as a constructor.

+ +

The GeneratorFunction constructor

+ +
+

Note: GeneratorFunction is not a global object, but could be obtained from generator function instance (see {{jsxref("GeneratorFunction")}} for more detail).

+
+ +
+

Note: Using the GeneratorFunction constructor to create functions is not recommended since it needs the function body as a string which may prevent some JS engine optimizations and can also cause other problems.

+
+ +

As all other objects, {{jsxref("GeneratorFunction")}} objects can be created using the new operator:

+ +
new GeneratorFunction (arg1, arg2, ... argN, functionBody)
+
+ +
+
arg1, arg2, ... argN
+
Zero or more names to be used by the function as formal argument names. Each must be a string that conforms to the rules for a valid JavaScript identifier or a list of such strings separated with a comma; for example "x", "theValue", or "a,b".
+
+ +
+
functionBody
+
A string containing the JavaScript statements comprising the function definition.
+
+ +

Invoking the Function constructor as a function (without using the new operator) has the same effect as invoking it as a constructor.

+ +

Function parameters

+ +

Default parameters

+ +

Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed. For more details, see default parameters.

+ +

Rest parameters

+ +

The rest parameter syntax allows representing an indefinite number of arguments as an array. For more details, see rest parameters.

+ +

The arguments object

+ +

You can refer to a function's arguments within the function by using the arguments object. See arguments.

+ + + +

Defining method functions

+ +

Getter and setter functions

+ +

You can define getters (accessor methods) and setters (mutator methods) on any standard built-in object or user-defined object that supports the addition of new properties. The syntax for defining getters and setters uses the object literal syntax.

+ +
+
get
+
+

Binds an object property to a function that will be called when that property is looked up.

+
+
set
+
Binds an object property to a function to be called when there is an attempt to set that property.
+
+ +

Method definition syntax

+ +

Starting with ECMAScript 2015, you are able to define own methods in a shorter syntax, similar to the getters and setters. See method definitions for more information.

+ +
var obj = {
+  foo() {},
+  bar() {}
+};
+ +

Constructor vs. declaration vs. expression

+ +

Compare the following:

+ +

A function defined with the Function constructor assigned to the variable multiply:

+ +
var multiply = new Function('x', 'y', 'return x * y');
+ +

A function declaration of a function named multiply:

+ +
function multiply(x, y) {
+   return x * y;
+} // there is no semicolon here
+
+ +

A function expression of an anonymous function assigned to the variable multiply:

+ +
var multiply = function(x, y) {
+   return x * y;
+};
+
+ +

A function expression of a function named func_name assigned to the variable multiply:

+ +
var multiply = function func_name(x, y) {
+   return x * y;
+};
+
+ +

Differences

+ +

All do approximately the same thing, with a few subtle differences:

+ +

There is a distinction between the function name and the variable the function is assigned to. The function name cannot be changed, while the variable the function is assigned to can be reassigned. The function name can be used only within the function's body. Attempting to use it outside the function's body results in an error (or undefined if the function name was previously declared via a var statement). For example:

+ +
var y = function x() {};
+alert(x); // throws an error
+
+ +

The function name also appears when the function is serialized via Function's toString method.

+ +

On the other hand, the variable the function is assigned to is limited only by its scope, which is guaranteed to include the scope in which the function is declared.

+ +

As the 4th example shows, the function name can be different from the variable the function is assigned to. They have no relation to each other. A function declaration also creates a variable with the same name as the function name. Thus, unlike those defined by function expressions, functions defined by function declarations can be accessed by their name in the scope they were defined in:

+ +

A function defined by 'new Function' does not have a function name. However, in the SpiderMonkey JavaScript engine, the serialized form of the function shows as if it has the name "anonymous". For example, alert(new Function()) outputs:

+ +
function anonymous() {
+}
+
+ +

Since the function actually does not have a name, anonymous is not a variable that can be accessed within the function. For example, the following would result in an error:

+ +
var foo = new Function("alert(anonymous);");
+foo();
+
+ +

Unlike functions defined by function expressions or by the Function constructor, a function defined by a function declaration can be used before the function declaration itself. For example:

+ +
foo(); // alerts FOO!
+function foo() {
+   alert('FOO!');
+}
+
+ +

A function defined by a function expression or by a function declaration inherits the current scope. That is, the function forms a closure. On the other hand, a function defined by a Function constructor does not inherit any scope other than the global scope (which all functions inherit).

+ +
/*
+ * Declare and initialize a variable 'p' (global)
+ * and a function 'myFunc' (to change the scope) inside which
+ * declare a varible with same name 'p' (current) and
+ * define three functions using three different ways:-
+ *     1. function declaration
+ *     2. function expression
+ *     3. function constructor
+ * each of which will log 'p'
+ */
+var p = 5;
+function myFunc() {
+    var p = 9;
+
+    function decl() {
+        console.log(p);
+    }
+    var expr = function() {
+        console.log(p);
+    };
+    var cons = new Function('\tconsole.log(p);');
+
+    decl();
+    expr();
+    cons();
+}
+myFunc();
+
+/*
+ * Logs:-
+ * 9  - for 'decl' by function declaration (current scope)
+ * 9  - for 'expr' by function expression (current scope)
+ * 5  - for 'cons' by Function constructor (global scope)
+ */
+
+ +

Functions defined by function expressions and function declarations are parsed only once, while those defined by the Function constructor are not. That is, the function body string passed to the Function constructor must be parsed each and every time the constructor is called. Although a function expression creates a closure every time, the function body is not reparsed, so function expressions are still faster than "new Function(...)". Therefore the Function constructor should generally be avoided whenever possible.

+ +

It should be noted, however, that function expressions and function declarations nested within the function generated by parsing a Function constructor 's string aren't parsed repeatedly. For example:

+ +
var foo = (new Function("var bar = \'FOO!\';\nreturn(function() {\n\talert(bar);\n});"))();
+foo(); // The segment "function() {\n\talert(bar);\n}" of the function body string is not re-parsed.
+ +

A function declaration is very easily (and often unintentionally) turned into a function expression. A function declaration ceases to be one when it either:

+ + + +
var x = 0;               // source element
+if (x === 0) {           // source element
+   x = 10;               // not a source element
+   function boo() {}     // not a source element
+}
+function foo() {         // source element
+   var y = 20;           // source element
+   function bar() {}     // source element
+   while (y === 10) {    // source element
+      function blah() {} // not a source element
+      y++;               // not a source element
+   }
+}
+
+ +

Examples

+ +
// function declaration
+function foo() {}
+
+// function expression
+(function bar() {})
+
+// function expression
+x = function hello() {}
+
+
+if (x) {
+   // function expression
+   function world() {}
+}
+
+
+// function declaration
+function a() {
+   // function declaration
+   function b() {}
+   if (0) {
+      // function expression
+      function c() {}
+   }
+}
+
+ +

Block-level functions

+ +

In strict mode, starting with ES2015, functions inside blocks are now scoped to that block. Prior to ES2015, block-level functions were forbidden in strict mode.

+ +
'use strict';
+
+function f() {
+  return 1;
+}
+
+{
+  function f() {
+    return 2;
+  }
+}
+
+f() === 1; // true
+
+// f() === 2 in non-strict mode
+
+ +

Block-level functions in non-strict code

+ +

In a word: Don't.

+ +

In non-strict code, function declarations inside blocks behave strangely. For example:

+ +
if (shouldDefineZero) {
+   function zero() {     // DANGER: compatibility risk
+      console.log("This is zero.");
+   }
+}
+
+ +

ES2015 says that if shouldDefineZero is false, then zero should never be defined, since the block never executes. However, it's a new part of the standard. Historically, this was left unspecified, and some browsers would define zero whether the block executed or not.

+ +

In strict mode, all browsers that support ES2015 handle this the same way: zero is defined only if shouldDefineZero is true, and only in the scope of the if-block.

+ +

A safer way to define functions conditionally is to assign a function expression to a variable:

+ +
var zero;
+if (shouldDefineZero) {
+   zero = function() {
+      console.log("This is zero.");
+   };
+}
+
+ +

Examples

+ +

Returning a formatted number

+ +

The following function returns a string containing the formatted representation of a number padded with leading zeros.

+ +
// This function returns a string padded with leading zeros
+function padZeros(num, totalLen) {
+   var numStr = num.toString();             // Initialize return value as string
+   var numZeros = totalLen - numStr.length; // Calculate no. of zeros
+   for (var i = 1; i <= numZeros; i++) {
+      numStr = "0" + numStr;
+   }
+   return numStr;
+}
+
+ +

The following statements call the padZeros function.

+ +
var result;
+result = padZeros(42,4); // returns "0042"
+result = padZeros(42,2); // returns "42"
+result = padZeros(5,4);  // returns "0005"
+
+ +

Determining whether a function exists

+ +

You can determine whether a function exists by using the typeof operator. In the following example, a test is performed to determine if the window object has a property called noFunc that is a function. If so, it is used; otherwise, some other action is taken.

+ +
 if ('function' === typeof window.noFunc) {
+   // use noFunc()
+ } else {
+   // do something else
+ }
+
+ +

Note that in the if test, a reference to noFunc is used—there are no brackets "()" after the function name so the actual function is not called.

+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.0
{{SpecName('ES5.1', '#sec-13', 'Function Definition')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}{{Spec2('ES6')}}New: Arrow functions, Generator functions, default parameters, rest parameters.
{{SpecName('ESDraft', '#sec-function-definitions', 'Function definitions')}}{{Spec2('ESDraft')}} 
+ +

Browser compatibility

+ + + +

{{Compat("javascript.functions")}}

+ +

See also

+ + diff --git "a/files/el/web/javascript/reference/functions/\317\200\317\201\316\277\316\265\317\200\316\271\316\273\316\265\316\263\316\274\316\255\316\275\316\265\317\202_\317\200\316\261\317\201\316\254\316\274\316\265\317\204\317\201\316\277\316\271/index.html" "b/files/el/web/javascript/reference/functions/\317\200\317\201\316\277\316\265\317\200\316\271\316\273\316\265\316\263\316\274\316\255\316\275\316\265\317\202_\317\200\316\261\317\201\316\254\316\274\316\265\317\204\317\201\316\277\316\271/index.html" new file mode 100644 index 0000000000..1802637dce --- /dev/null +++ "b/files/el/web/javascript/reference/functions/\317\200\317\201\316\277\316\265\317\200\316\271\316\273\316\265\316\263\316\274\316\255\316\275\316\265\317\202_\317\200\316\261\317\201\316\254\316\274\316\265\317\204\317\201\316\277\316\271/index.html" @@ -0,0 +1,221 @@ +--- +title: Προεπιλεγμένες παράμετροι +slug: Web/JavaScript/Reference/Functions/Προεπιλεγμένες_παράμετροι +tags: + - ECMAScript 2015 + - JavaScript + - Συναρτήσεις +translation_of: Web/JavaScript/Reference/Functions/Default_parameters +--- +
{{jsSidebar("Συναρτήσεις")}}
+ +

Οι προεπιλεγμένες παράμετροι συναρτήσεων επιτρέπουν την αρχικοποίηση των παραμέτρων με προεπιλεγμένες τιμες, αν η τιμή λείπει ή ειναι τύπου undefined.

+ +
{{EmbedInteractiveExample("pages/js/functions-default.html")}}
+ + + +

Σύνταξη

+ +
function [όνομα]([παράμ1[ = προεπιλεγμένηΤιμή1 ][, ..., παράμN[ = προεπιλεγμένηΤιμήN ]]]) {δηλώσεις
+}
+
+ +

Περιγραφή

+ +

Στην JavaScript, οι προεπιλεγμένες παράμετροι των συναρτήσεων ειναι τύπου {{jsxref("undefined")}}. Ωστόσο, σε κάποιες καταστάσεις μπορεί να χρειαστεί να θέσουμε μια διαφορετική προεπιλεγμένη τιμή. Σε αυτή την περίπτωση μπορούν βοηθήσουν οι προεπιλεγμένες παράμετροι.

+ +

Στο παρελθόν, η γενική στρατηγική ορισμού προεπιλεγμένων τιμών, ηταν ο έλεγχος των τιμών στο σώμα την συνάρτησης και η εκχώρηση τιμής στην περίπτωση που ήταν τύπου undefined. Αν στο επόμενο παράδειγμα, δεν δοθεί τιμή για την b οταν κλήθει η συναρτηση, η τιμή της θα ήταν undefined  κατα την εκτίμηση του a*b και η κλήση της multiply θα επέστρεφε NaN. Ωστόσο, αυτό αποτρέπεται στην δεύτερη γραμμή του παραδείγματος:

+ +
function multiply(a, b) {
+  b = (typeof b !== 'undefined') ?  b : 1;
+  return a * b;
+}
+
+multiply(5, 2); // 10
+multiply(5, 1); // 5
+multiply(5);    // 5
+
+ +

Με τις προεπιλεγμένες παραμέτρους στην ES2015, ο έλεγχος στο σώμα της συνάρτησης δεν ειναι πια απαραίτητος. Τωρα μπορούμε απλα να θέσουμε 1 ως προεπιλεγμένη τιμή της b στην κεφαλή της συνάρτησης:

+ +
function multiply(a, b = 1) {
+  return a * b;
+}
+
+multiply(5, 2); // 10
+multiply(5, 1); // 5
+multiply(5);    // 5
+
+ +

Παραδείγματα

+ +

Περνώντας undefined σε αντίθεση με άλλες falsy τιμες

+ +

Στην δεύτερη κλήση εδω, ακόμα και αν η δεύτερη παράμετρος είναι ρητά undefined (αλλά οχι null ή άλλες falsy τιμές) κατα την κλήση, η τιμή της παραμέτρου num είναι η προεπιλεγμένη.

+ +
function test(num = 1) {
+  console.log(typeof num);
+}
+
+test();          // 'number' (η num παίρνει τιμή 1)
+test(undefined); // 'number' (η num επίσης παίρνει τιμή 1)
+
+// test with other falsy values:
+test('');        // 'string' (η num παίρνει τιμή '')
+test(null);      // 'object' (η num παίρνει τιμή null)
+
+ +

Εκτίμηση κατα την κλήση

+ +

Η προεπιλεγμένη παράμετρος εκτιμάται κατα την κλήση, οπότε αντίθετα με την Python για παραδειγμα, ενα νεο αντικείμενο δημιουργείται καθε φορά που καλείται η συνάρτηση.

+ +
function append(value, array = []) {
+  array.push(value);
+  return array;
+}
+
+append(1); //[1]
+append(2); //[2], όχι [1, 2]
+
+
+ +

Αυτό εφαρμόζεται ακομα και στις συναρτήσεις και τις μεταβλητές:

+ +
function callSomething(thing = something()) {
+ return thing;
+}
+
+function something() {
+  return 'sth';
+}
+
+callSomething();  //sth
+ +

Οι προεπιλεγμένες παράμετροι ειναι διαθέσιμες σε επόμενες προεπιλεγμένες παραμέτρους

+ +

Οι παράμετροι που εχουν ήδη συναντηθεί είναι διαθέσιμες και στις επόμενες προεπιλεγμένες παραμέτρους:

+ +
function singularAutoPlural(singular, plural = singular + 's',
+                            rallyingCry = plural + ' ATTACK!!!') {
+  return [singular, plural, rallyingCry];
+}
+
+//["Gecko","Geckos", "Geckos ATTACK!!!"]
+singularAutoPlural('Gecko');
+
+//["Fox","Foxes", "Foxes ATTACK!!!"]
+singularAutoPlural('Fox', 'Foxes');
+
+//["Deer", "Deer", "Deer ... change."]
+singularAutoPlural('Deer', 'Deer', 'Deer peaceably and respectfully \
+   petition the government for positive change.')
+
+ +

Αυτή η λειτουργικότητα υπολογίζεται σταδιακά. Το επόμενο παράδειγμα επιδεικνύει το πως χειρίζονται άλλες ακραίες περιπτώσεις.

+ +
function go() {
+  return ':P';
+}
+
+function withDefaults(a, b = 5, c = b, d = go(), e = this,
+                      f = arguments, g = this.value) {
+  return [a, b, c, d, e, f, g];
+}
+
+function withoutDefaults(a, b, c, d, e, f, g) {
+  switch (arguments.length) {
+    case 0:
+      a;
+    case 1:
+      b = 5;
+    case 2:
+      c = b;
+    case 3:
+      d = go();
+    case 4:
+      e = this;
+    case 5:
+      f = arguments;
+    case 6:
+      g = this.value;
+    default:
+  }
+  return [a, b, c, d, e, f, g];
+}
+
+withDefaults.call({value: '=^_^='});
+// [undefined, 5, 5, ":P", {value:"=^_^="}, arguments, "=^_^="]
+
+
+withoutDefaults.call({value: '=^_^='});
+// [undefined, 5, 5, ":P", {value:"=^_^="}, arguments, "=^_^="]
+
+ +

Συναρτήσεις που ορίζονται μεσα στο σώμα της συνάρτησης

+ +

Εισάχθηκε στο Gecko 33 {{geckoRelease(33)}}. Οι συναρτήσεις που ορίζονται στο σώμα της συνάρτησης δεν μπορούν να αναφέρονται στίς προεπιλεγμένες παραμέτρους και εμφανίζουν ενα {{jsxref("ReferenceError")}} (αυτή τη στιγμή {{jsxref("TypeError")}} στο SpiderMonkey, βλέπε {{bug(1022967)}}). Οι προεπιλεγμένες παράμετροι εκτελούνται παντα πρώτες και στην συνέχεια εκτελούνται οι δηλώσεις που βρίσκονται στο σώμα της συνάρτησης.

+ +
// Doesn't work! Throws ReferenceError.
+function f(a = go()) {
+  function go() { return ':P'; }
+}
+
+ +

Παράμετροι χωρίς προεπιλεγμένες τιμες μετα τις προεπιλεγμενες παραμέτρους

+ +

Πριν απο το Gecko 26 {{geckoRelease(26)}}, ο ακόλουθος κώδικας προκαλούσε ένα {{jsxref("SyntaxError")}}. Αυτό επιδιορθώθηκε στο {{bug(777060)}} και έχει την αναμενόμενη λειτουργία σε επόμενες εκδόσεις. Οι παράμετροι ορίζονται ακόμα απο τα αριστερά στα δεξιά, αντικαθιστώντας προεπιλεγμένες παραμέτρους ακόμα και αν υπάρχουν επόμενες παράμετροι χωρίς προεπιλεγμένες τιμές.

+ +
function f(x = 1, y) {
+  return [x, y];
+}
+
+f(); // [1, undefined]
+f(2); // [2, undefined]
+
+ +

Αποδόμηση παραμέτρων στον ορισμό προεπιλεγμένων τιμών

+ +

Στον ορισμό προεπιλεγμένων παραμέτρων μπορεί να χρησιμοποιηθεί αποδομημένη ανάθεση:

+ +
function f([x, y] = [1, 2], {z: z} = {z: 3}) {
+  return x + y + z;
+}
+
+f(); // 6
+ +

Προδιαγραφές

+ + + + + + + + + + + + + + + + + + + +
ΠροδιαγραφήΚατάστασηΣχόλιο
{{SpecName('ES2015', '#sec-function-definitions', 'Function Definitions')}}{{Spec2('ES2015')}}Αρχικός ορισμός.
{{SpecName('ESDraft', '#sec-function-definitions', 'Function Definitions')}}{{Spec2('ESDraft')}} 
+ +

Συμβατότητα περιηγητών

+ +
+ + +

{{Compat("javascript.functions.default_parameters")}}

+
+ +

Δείτε επίσης

+ + diff --git a/files/el/web/javascript/reference/global_objects/index.html b/files/el/web/javascript/reference/global_objects/index.html new file mode 100644 index 0000000000..f59e3e8592 --- /dev/null +++ b/files/el/web/javascript/reference/global_objects/index.html @@ -0,0 +1,193 @@ +--- +title: Standard built-in objects +slug: Web/JavaScript/Reference/Global_Objects +tags: + - JavaScript + - NeedsTranslation + - Reference + - TopicStub +translation_of: Web/JavaScript/Reference/Global_Objects +--- +
{{jsSidebar("Objects")}}
+ +

This chapter documents all of JavaScript's standard, built-in objects, including their methods and properties.

+ +

The term "global objects" (or standard built-in objects) here is not to be confused with the global object. Here, global objects refer to objects in the global scope. The global object itself can be accessed using the {{jsxref("Operators/this", "this")}} operator in the global scope (but only if ECMAScript 5 strict mode is not used; in that case it returns {{jsxref("undefined")}}). In fact, the global scope consists of the properties of the global object, including inherited properties, if any.

+ +

Other objects in the global scope are either created by the user script or provided by the host application. The host objects available in browser contexts are documented in the API reference. For more information about the distinction between the DOM and core JavaScript, see JavaScript technologies overview.

+ +

Standard objects by category

+ +

Value properties

+ +

These global properties return a simple value; they have no properties or methods.

+ + + +

Function properties

+ +

These global functions—functions which are called globally rather than on an object—directly return their results to the caller.

+ + + +

Fundamental objects

+ +

These are the fundamental, basic objects upon which all other objects are based. This includes objects that represent general objects, functions, and errors.

+ + + +

Numbers and dates

+ +

These are the base objects representing numbers, dates, and mathematical calculations.

+ + + +

Text processing

+ +

These objects represent strings and support manipulating them.

+ + + +

Indexed collections

+ +

These objects represent collections of data which are ordered by an index value. This includes (typed) arrays and array-like constructs.

+ + + +

Keyed collections

+ +

These objects represent collections which use keys; these contain elements which are iterable in the order of insertion.

+ + + +

Vector collections

+ +

{{Glossary("SIMD")}} vector data types are objects where data is arranged into lanes.

+ + + +

Structured data

+ +

These objects represent and interact with structured data buffers and data coded using JavaScript Object Notation (JSON).

+ + + +

Control abstraction objects

+ + + +

Reflection

+ + + +

Internationalization

+ +

Additions to the ECMAScript core for language-sensitive functionalities.

+ + + +

WebAssembly

+ + + +

Other

+ + diff --git a/files/el/web/javascript/reference/index.html b/files/el/web/javascript/reference/index.html new file mode 100644 index 0000000000..4205970b93 --- /dev/null +++ b/files/el/web/javascript/reference/index.html @@ -0,0 +1,51 @@ +--- +title: JavaScript reference +slug: Web/JavaScript/Reference +tags: + - JavaScript + - NeedsTranslation + - TopicStub + - 'l10n:priority' +translation_of: Web/JavaScript/Reference +--- +
{{JsSidebar}}
+ +

This part of the JavaScript section on MDN serves as a repository of facts about the JavaScript language. Read more about this reference.

+ +

Global Objects

+ +

This chapter documents all the JavaScript standard built-in objects, along with their methods and properties.

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects', 'Standard_objects_by_category')}}
+ +

Statements

+ +

This chapter documents all the JavaScript statements and declarations.

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Statements', 'Statements_and_declarations_by_category')}}
+ +

Expressions and operators

+ +

This chapter documents all the JavaScript expressions and operators.

+ +
{{page('/en-US/docs/Web/JavaScript/Reference/Operators', 'Expressions_and_operators_by_category')}}
+ +

Functions

+ +

This chapter documents how to work with JavaScript functions to develop your applications.

+ + + +

Additional reference pages

+ + diff --git a/files/el/web/javascript/reference/operators/comma_operator/index.html b/files/el/web/javascript/reference/operators/comma_operator/index.html new file mode 100644 index 0000000000..97e396cc1e --- /dev/null +++ b/files/el/web/javascript/reference/operators/comma_operator/index.html @@ -0,0 +1,154 @@ +--- +title: Τελεστής Κόμμα +slug: Web/JavaScript/Reference/Operators/Comma_Operator +tags: + - JavaScript + - Κόμμα + - Τελεστής + - Τελεστής Κόμμα +translation_of: Web/JavaScript/Reference/Operators/Comma_Operator +--- +
{{jsSidebar("Τελεστές")}}
+ +

Ο τελεστής κόμμα αποτιμά κάθε τελεστέο του (από τα αριστερά προς τα δεξιά) και επιστρέφει τη τιμή του τελευταίου τελεστέου.

+ +

Σύνταξη

+ +
έκφραση1, έκφραση2, έκφραση3...
+ +

Παράμετροι

+ +
+
έκφραση1, έκφραση2, έκφραση3...
+
Οποιαδήποτε έκφραση.
+
+ +

Περιγραφή

+ +

Μπορείτε να χρησιμοποιήσετε τον τελεστή κόμμα όποτε θέλετε να συμπεριλάβετε πολλαπλές εκφράσεις σε σημείο που απαιτείται μία έκφραση. Η πιο κοινή χρήση αυτού του τελεστή είναι η προμήθεια πολλαπλών παραμέτρων σε έναν for βρόχο.

+ +

Παραδείγματα

+ +

Αν a είναι ένας διδιάστατος πίνακας με 10 στοιχεία σε κάθε πλευρά, ο ακόλουθος κώδικας χρησιμοποιεί τον τελεστή κόμμα για να αυξήσει δύο μεταβλητές με την μία.

+ +

Ο ακόλουθος κώδικας εκτυπώνει τις τιμές των διαγώνιων στοιχείων του πίνακα:

+ +
for (var i = 0, j = 9; i <= 9; i++, j--)
+  console.log('a[' + i + '][' + j + '] = ' + a[i][j]);
+ +

Παρατηρήστε ότι το κόμμα στις αναθέσεις όπως στην var δήλωση μπορεί να μην έχει το κανονικό αποτέλεσμα του τελεστή κόμμα επειδή δεν υπάρχει μέσα σε έκφραση. Στο ακόλουθο παράδειγμα, το a παίρνει την τιμή του b = 3 (η οποία είναι 3), αλλά η έκφραση c = 4 επίσης αποτιμάται και το αποτέλεσμά της επιστρέφει στην κονσόλα (δηλαδή, 4). Αυτό οφείλεται στην προτεραιότητα τελεστών και προσεταιριστικότητα.

+ +
// Παρατηρήστε οτι τα παρακάτω δημιουργούν globals το οποίο απαγορεύεται στο strict mode.
+
+a = b = 3, c = 4; // Επιστρέφει 4 στην κονσόλα
+console.log(a); // 3 (αριστερότερο)
+
+x = (y = 5, z = 6); // Επιστρέφει 6 στην κονσόλα
+console.log(x); // 6 (δεξιότερο)
+
+ +

Ο τελεστής κόμμα είναι τελείως διαφορετικός από το κόμμα μέσα σε πίνακες, αντικείμενα, και ορίσματα και παραμέτρους συνάρτησης.

+ +

Επεξεργασία και επιστροφή

+ +

Ένα παράδειγμα ακόμα που μπορεί να κάνει κάποιος με τον τελεστή κόμμα είναι επεξεργασία πρίν την επιστροφή. Όπως αναφέρθηκε, μόνο το τελευταίο στοιχείο θα γυρίσει, πλην όμως, όλα τα άλλα πρόκειται να αποτιμηθούν εξίσου. Οπότε, κάποιος θα μπορούσε να κάνει:

+ +
function myFunc() {
+  var x = 0;
+
+  return (x += 1, x); // Ίδιο με το return ++x;
+}
+ +

Προδιαγραφές

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ΠροδιαγραφήΚατάστασηΣχόλιο
{{SpecName('ESDraft', '#sec-comma-operator', 'Comma operator')}}{{Spec2('ESDraft')}} 
{{SpecName('ES6', '#sec-comma-operator', 'Comma operator')}}{{Spec2('ES6')}} 
{{SpecName('ES5.1', '#sec-11.14', 'Comma operator')}}{{Spec2('ES5.1')}} 
{{SpecName('ES1', '#sec-11.14', 'Comma operator')}}{{Spec2('ES1')}}Αρχικός Ορισμός
+ +

Συμβατότητα Προγράμματος Περιήγησης

+ +

{{CompatibilityTable}}

+ +
+ + + + + + + + + + + + + + + + + + + + + +
ΧαρακτηριστικόChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Βασική Υποστήριξη{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}3.0{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
ΧαρακτηριστικόAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Βασική Υποστήριξη{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

Δείτε επίσης

+ + diff --git a/files/el/web/javascript/reference/operators/index.html b/files/el/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..9ed1cba01e --- /dev/null +++ b/files/el/web/javascript/reference/operators/index.html @@ -0,0 +1,301 @@ +--- +title: Expressions and operators +slug: Web/JavaScript/Reference/Operators +tags: + - JavaScript + - εκφράσεις + - τελεστές +translation_of: Web/JavaScript/Reference/Operators +--- +
{{jsSidebar("Operators")}}
+ +

Στο κεφάλαιο αυτό περιγράφονται όλοι οι τελεστές, οι εκφράσεις και οι λέξεις κλειδιά της JavaScript.

+ +

Εκφράσεις και τελεστές ανά κατηγορία

+ +

Για αλφαβητική ταξινόμηση δείτε το μενού στα αριστερά.

+ +

Πρωταρχικές εκφράσεις

+ +

Βασικές λέξεις κλειδιά και γενικές εκφράσεις στην JavaScript.

+ +
+
{{jsxref("Operators/this", "this")}}
+
Η λέξη κλειδί this αναφέρεται στο προγραμματιστικό πλαίσιο της εκάστοτε συνάρτησης.
+
{{jsxref("Operators/function", "function")}}
+
Η λέξη κλειδί function ορίζει μια εκφραση δήλωσης συνάρτησης (function).
+
{{jsxref("Operators/class", "class")}}
+
Η λέξη κλειδί class ορίζει μια έκφραση δήλωσης κλάσης(class).
+
{{jsxref("Operators/function*", "function*")}}
+
Η λέξη κλειδί function* ορίζει μια έκφραση δήλωσης συνάρτησης γεννήτριας (generator function).
+
{{jsxref("Operators/yield", "yield")}}
+
Διακόπτει και συνεχίζει μια συνάρτηση γεννήτρια.
+
{{jsxref("Operators/yield*", "yield*")}}
+
Αναθέτει σε μια άλλη συνάρτηση γεννήτριας ή σε κάποιο επαναλήψιμο αντικείμενο.
+
{{experimental_inline}} {{jsxref("Operators/async_function", "async function*")}}
+
Η async function ορίζει μια έκφραση δήλωσης ασυγχρονης συνάρτησης (async function).
+
{{experimental_inline}} {{jsxref("Operators/await", "await")}}
+
Διακόπτει και συνεχίζει μια ασύγχρονη συνάρτηση, και περιμένει την ασύχρονη απάντηση/απόρριψη από αυτή.
+
{{jsxref("Global_Objects/Array", "[]")}}
+
Βασική σύνταξη αρχικοποίησης ενός πίνακα (Array).
+
{{jsxref("Operators/Object_initializer", "{}")}}
+
Βασική σύνταξη αρχικοποίησης ενός αντικειμένου (Object).
+
{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}
+
Βασική σύνταξη αρχικοποίησης μιας κοινής έκφρασης (Regular Expression).
+
{{jsxref("Operators/Grouping", "( )")}}
+
Τελεστής ομαδοποίησης.
+
+ +

Εκφράσεις αριστερής πλευράς (Left-hand-side)

+ +

Οι τιμές στο αριστερό μέρος αποτελούν τον προορισμό της ανάθεσης.

+ +
+
{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}
+
Οι τελεστές μέλους παρέχουν πρόσβαση στις ιδιότητες ή στις μεθόδους ενός αντικειμένου.
+ (object.property and object["property"]).
+
{{jsxref("Operators/new", "new")}}
+
Ο τελεστής new δημιουργεί ένα στιγμιότυπο ενός κατασκευαστή (constructor).
+
new.target
+
Στους κατασκευαστές, new.target αναφέρεται στους κατασκευαστές που κλήθηκαν από το {{jsxref("Operators/new", "new")}}.
+
{{jsxref("Operators/super", "super")}}
+
Η λέξη κλειδί super καλεί τον κατασκευαστή του γονέα (parent constructor).
+
{{jsxref("Operators/Spread_operator", "...obj")}}
+
Η σύνταξη διάδοσης (Spread syntax) επιτρέπει σε μια έκφραση να εξαπλωθεί σε σημεία όπου αναμένονται πολλαπλά ορίσματα (πχ. κλήση συνάρτησης) ή πολλαπλά στοιχεία (πχ αρχική δήλωση πινάκων).
+
+ +

Επαυξηση και μείωση

+ +

Τελεστές Postfix/prefix επαύξησης και  postfix/prefix μείωσης.

+ +
+
{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}
+
Τελεστής αύξησης μετά την μεταβλητή (Postfix).
+
{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}
+
Τελεστής μείωσης μετά την μεταβλητή (Postfix).
+
{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}
+
Τελεστής αύξησης πριν την μεταβλητή (Prefix).
+
{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}
+
Τελεστής μείωσης πριν την μεταβλητή (Prefix).
+
+ +

Μοναδιαίοι τελεστές

+ +

Μοναδιαία είναι η διαδικασία που απαιτεί μόνο εναν τελεστή.

+ +
+
{{jsxref("Operators/delete", "delete")}}
+
Ο τελεστής delete διαγράφει ένα χαρακτηριστικό από ένα αντικείμενο.
+
{{jsxref("Operators/void", "void")}}
+
Ο τελεστής void απορρίπτει την επιστρεφόμενη τιμή μιας έκφρασης.
+
{{jsxref("Operators/typeof", "typeof")}}
+
Ο τελεστής typeof προσδιορίζει τον τύπο ενός δεδομένου αντικειμένου.
+
{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}
+
Ο τελεστής unary plus μετατρέπει τον όρο πράξης του σε αριθμό (Number type).
+
{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}
+
Ο τελεστής unary negation μετατρέπει τον όρο πράξης του σε αριθμό (Number type) και ακολούθως τον μετατρέπει σε αρνητικό.
+
{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}
+
Τελεστής άρνησης σε επίπεδο bit (Bitwise NOT).
+
{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}
+
Τελεστής λογικής άρνησης (Logical NOT).
+
+ +

Αριθμητικοί τελεστές

+ +

Οι αριθμητικοί τελεστές δέχονται αριθμητικές τιμές σαν ορίσματα πράξης (είτε αριθμούς, είτε μεταβλητές) και επιστρέφουν μια απλή αριθμητική τιμή.

+ +
+
{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}
+
Τελεστής πρόσθεσης.
+
{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}
+
Τελεστής αφαίρεσης.
+
{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}
+
Τελεστής διαίρεσης.
+
{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}
+
Τελεστής πολλαπλασιασμού.
+
{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}
+
Τελεστής υπολοίπου διαίρεσης.
+
+ +
+
{{jsxref("Operators/Arithmetic_Operators", "**", "#Exponentiation")}}
+
Εκθετικός τελεστής.
+
+ +

Σχεσιακοί τελεστές

+ +

Ενας τελεστής σύγκρισης συγκρίνει τα ορίσματα πράξης και επιστρέφει μια Boolean τιμή βασισμένη στο αν η σύγκριση είναι αληθής.

+ +
+
{{jsxref("Operators/in", "in")}}
+
Ο τελεστής in προσδιορίζει αν ενα αντικείμενο έχει ένα συγκεκριμένο χαρακτηριστικό.
+
{{jsxref("Operators/instanceof", "instanceof")}}
+
Ο τελεστής instanceof προσδιορίζει αν ένα αντικείμενο είναι στιγμιότυπο ενός άλλου αντικειμένου.
+
{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}
+
Τελεστής 'μικρότερο από'.
+
{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}
+
Τελεστής 'μεγαλύτερο από'.
+
{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}
+
Τελεστής 'μικρότερο από ή ίσο'.
+
{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}
+
Τελεστής 'μεγαλύτερο από ή ίσο'.
+
+ +
+

Σημείωση: το =>  δεν είναι τελεστής αλλά αποτελεί σημειογραφία για τις Arrow functions.

+
+ +

Τελεστές ισότητας

+ +

Το αποτέλεσμα των τελεστών ισότητας είναι πάντα τύπου Boolean και βασίζεται στο αν η σύγκριση είανι αληθής.

+ +
+
{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}
+
Τελεστής ισότητας.
+
{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}
+
Τελεστής ανισότητας, διαφορετικότητας.
+
{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}
+
Τελεστής ισότητας ταυτότητας.
+
{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}
+
Τελεστής ανισότητας ταυτότητας.
+
+ +

Τελεστές κύλισης bits

+ +

Λειτουργία κύλισης όλων των bits των ορισμάτων.

+ +
+
{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}
+
Τελεστής αριστερής κύλισης bit (Bitwise left shift).
+
{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}
+
Τελεστής δεξιάς κύλισης bit (Bitwise right shift).
+
{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}
+
Τελεστής δεξιάς κύλισης bit χωρίς πρόσημο (Bitwise right shift).
+
+ +

Δυαδικοί τελεστές bits

+ +

Οι δυαδικοί τελεστές bits χειριζονται τα ορίσματα τους σαν σετ απο 32 bits (0,1) και επιστρέφουν μια αριθμητική τιμή.

+ +
+
{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}
+
Bitwise AND.
+
{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}
+
Bitwise OR.
+
{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}
+
Bitwise XOR.
+
+ +

Δυαδικοί λογικοί τελεστές

+ +

Οι λογικοί τελεστές τυπικά χρησιμοποιούνται με boolean (λογικές) τιμές, και επιστρέφουν μια επίσης boolean τιμή.

+ +
+
{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}
+
Λογικό 'και' (AND).
+
{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}
+
Λογικό 'ή' (OR).
+
+ +

Τριαδικός υποθετικός τελεστής

+ +
+
{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}
+
+

Ο υποθετικός τελεστής επιστρέφει μια εκ των δύο τιμών, βάση της λογική τιμής της δεδομένης συνθήκης.

+
+
+ +

Τελεστές ανάθεσης.

+ +

Ένας τελεστής ανάθεσης αναθέτει μια τιμή στο αριστερό όρισμα βάση της τιμής του δεξιού ορίσματος.

+ +
+
{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}
+
Τελεστής ανάθεσης.
+
{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}
+
Τελεστής ανάθεσης πολλαπλάσιου.
+
{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}
+
Τελεστής ανάθεσης διαιρεταίου.
+
{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}
+
Τελεστής ανάθεσης υπολοίπου.
+
{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}
+
Τελεστής ανάθεσης αθροίσματος.
+
{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}
+
Τελεστής ανάθεσης αφαίρεσης.
+
{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}
+
Τελεστής ανάθεσης αριστερής κύλισης bit.
+
{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}
+
Τελεστής ανάθεσης δεξιάς κύλισης bit.
+
{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}
+
Τελεστής ανάθεσης δεξιάς κύλισης bit χωρίς πρόσημο.
+
{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}
+
Τελεστής ανάθεσης λογικού AND σε επίπεδο bits.
+
{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}
+
Τελεστής ανάθεσης λογικού XOR σε επίπεδο bits.
+
{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}
+
Τελεστής ανάθεσης λογικού OR σε επίπεδο bits.
+
{{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}
+ {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}
+
+

Η ανάθεση διάσπασης(destructuring) επιτρέπει την απευθείας ανάθεση των  χαρακτηριστικών, ενός αντικειμένου ή ενός πίνακα, σε μεταβλητές.

+
+
+ +

Τελεστης κόμμα ',' (comma)

+ +
+
{{jsxref("Operators/Comma_Operator", ",")}}
+
Ο τελεστής κόμμα(',') επιτρέπει σε πολλαπλές εκφράσεις να εκτιμηθούν σε μία μόνο δήλωση, και επιστρέφει το αποτέλεσμα της τελευταίας εκφρασης.
+
+ +

Non-standard features

+ +
+
{{non-standard_inline}} {{jsxref("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}}
+
Η λέξη κλειδί function μπορεί να χρησιμοποιηθεί για να ορίσει για συνάρτηση γεννήτρια μέσα σε μια έκφραση. Για να γίνει η συνάρτηση, συναρτηση γεννήτριας το σώμα της θα πρέπει να περιέχει τουλαχιστον μια  {{jsxref("Operators/yield", "yield")}} εκφραση.
+
{{non-standard_inline}} {{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}}
+
The expression closure syntax is a shorthand for writing simple function.
+
{{non-standard_inline}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}
+
Array comprehensions.
+
{{non-standard_inline}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}
+
Generator comprehensions.
+
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1', '#sec-11', 'Expressions')}}{{Spec2('ES1')}}Initial definition
{{SpecName('ES5.1', '#sec-11', 'Expressions')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}{{Spec2('ES6')}}New: Spread operator, destructuring assignment, super keyword.
{{SpecName('ESDraft', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}{{Spec2('ESDraft')}} 
+ +

See also

+ + -- cgit v1.2.3-54-g00ecf