From a06ab8e309a5b498c1e95f3788f1e85db7a34a3d Mon Sep 17 00:00:00 2001 From: Sascha Schulz <sschulz@dh-software.de> Date: Di, 06 Jun 2023 16:00:22 +0200 Subject: [PATCH] add examples for destructuring and try-catch-finally --- templates/007-js/destructuring-2.js | 5 +++++ templates/007-js/try-catch-finally.js | 19 +++++++++++++++++++ templates/007-js/destructuring-1.js | 5 +++++ 3 files changed, 29 insertions(+), 0 deletions(-) diff --git a/templates/007-js/destructuring-1.js b/templates/007-js/destructuring-1.js new file mode 100644 index 0000000..e62e320 --- /dev/null +++ b/templates/007-js/destructuring-1.js @@ -0,0 +1,5 @@ +const o = { a: [0, {b: [0, 5]}, 2]}; + +const { /* Destructuring-Ausdruck */ } = o; + +console.log(x); diff --git a/templates/007-js/destructuring-2.js b/templates/007-js/destructuring-2.js new file mode 100644 index 0000000..b6c7516 --- /dev/null +++ b/templates/007-js/destructuring-2.js @@ -0,0 +1,5 @@ +const o = { a: [0, {b: [0, { c: [{ x: 5 }, { d: 3}] }]}, 2]}; + +const { /* Destructuring-Ausdruck */ } = o; + +console.log(x); diff --git a/templates/007-js/try-catch-finally.js b/templates/007-js/try-catch-finally.js new file mode 100644 index 0000000..16f61a2 --- /dev/null +++ b/templates/007-js/try-catch-finally.js @@ -0,0 +1,19 @@ +function throwError() { + try { + throw new Error("Fehler!"); + + return "Hello World!"; + } + catch(e) { + return e.message; + } + finally { + console.log("Finally wird immer ausgeführt"); + + return "Finally hat Vorrang!"; + } +} + +const result = throwError(); + +console.log(result); -- Gitblit v1.9.3