0Pricing
Mojo Academy · Lektion

Kopien und gemeinsam genutzter Zustand

Wann sich Änderungen auswirken und wann nicht.

Kopien und gemeinsam genutzter Zustand ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

When Do Changes Spread?

Sometimes editing one variable also edits another, and sometimes it does not. The difference is copy versus shared state. 🔍

A Copy Is Self-Contained

When you get a copy, you hold separate data. Editing it cannot reach back and disturb the value you copied from.

var a = 1
var b = a
b = 2

Shared State Is One Thing, Two Names

With shared state, two variables point at the same underlying data. A change through one is visible through the other.

The Telltale Sign

Ask: after I edit one variable, did the other one change too? If yes, they shared; if no, you had a copy.

Mojo Copies By Default

For value types, Mojo gives you a copy on assignment. So in everyday code, changes stay nicely contained.

var first = 7
var second = first
second = 8

Structs Copy Their Fields

Copy a struct and you copy each field inside it. The new struct is fully independent from the original.

Why Sharing Causes Surprises

Shared state means a distant edit can silently change your value. That spooky action at a distance is a classic source of bugs.

Sharing Has Its Uses

Sharing is not evil; sometimes you want one source of truth. The key is to choose it on purpose, not by accident.

Reading Code With This Lens

When you see an assignment, picture whether it makes a copy or a link. That habit predicts how edits will travel.

var original = 50
var backup = original

A Quick Comparison

Copy: edits stay put. Shared: edits ripple. Mojo's default leans toward copies, so ripples are the exception, not the rule.

Independence You Can Trust

Knowing copies are independent lets you change a value boldly, sure that other parts of your program stay stable. ✅

Quick Check

Two variables point at the same underlying data. You edit one. What do you expect?

Recap

A copy keeps edits contained; shared state lets them ripple. Mojo copies value types by default, so surprises are rare. 🎯

Häufig gestellte Fragen

Ist die Lektion „Kopien und gemeinsam genutzter Zustand“ kostenlos?

Ja — der vollständige Text von „Kopien und gemeinsam genutzter Zustand“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Kopien und gemeinsam genutzter Zustand“?

Wann sich Änderungen auswirken und wann nicht. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Kopien und gemeinsam genutzter Zustand“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Was Wertsemantik bedeutet
  2. Kopien und gemeinsam genutzter Zustand
  3. Mojos sichere Standardeinstellung
  4. Ein erster Blick auf Mutation
← Zurück zu Mojo Academy