JavaScript-Variable: Deklarieren, Wert mit Beispiel zuweisen

Anonim

Variablen werden zum Speichern von Werten (Name = "John") oder Ausdrücken (Summe = x + y) verwendet.

Deklarieren Sie Variablen in JavaScript

Bevor Sie eine Variable verwenden, müssen Sie sie zuerst deklarieren. Sie müssen das Schlüsselwort var verwenden , um eine Variable wie folgt zu deklarieren:

var name;

Weisen Sie der Variablen einen Wert zu

Sie können der Variablen entweder beim Deklarieren der Variablen oder nach dem Deklarieren der Variablen einen Wert zuweisen.

var name = "John";

ODER

var name;name = "John";

Variablen benennen

Obwohl Sie die Variablen beliebig benennen können, ist es eine gute Programmierpraxis, den Variablen beschreibende und aussagekräftige Namen zu geben. Darüber hinaus sollten Variablennamen mit einem Buchstaben beginnen und zwischen Groß- und Kleinschreibung unterscheiden. Daher unterscheiden sich die Variablen student name und studentName, da der Buchstabe n in einem Namen unterschiedlich ist (n und N).

Versuchen Sie dies selbst:

 Variablen !!! </ title><script type = "text />var one = 22;var zwei = 3;var add = eins + zwei;var minus = eins - zwei;var multiplizieren = eins * zwei;var dividieren = eins / zwei;document.write ("Erste Nr.: =" + eins + "<br />Zweite Nr.: =" + zwei + "<br />");document.write (eins + "+" + zwei + + add + "<br />");document.write (eins + "-" + zwei + + minus + "<br />");document.write (eins + "*" + zwei + + multiplizieren + "<br />");document.write (eins + "/" + zwei + + dividieren + "<br />");</ script></ head><body></ body></ html></pre> <form class="hidden" code-box" name="sample"> Dieser Code kann bearbeitet werden. Klicken Sie zum Ausführen auf Ausführen<textarea name="codeguru"> </textarea>
<p><input type="submit" value="Lauf" style="background-color:#df5035;" color:#ffffff;"></p>


										</div>
									</article>
									
<div id="container-5533149ee6411a5f99b370c693e87966"></div>								</div>
							</div>
						</div>
					</div>
				</div>
				
<aside class="col-lg-4 sidebar sidebar--right">
	<div class="widget widget-popular-posts">
		<h2 class="widget-title">Beliebte Beiträge</h2>
		<ul class="post-list-small">
			<li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8001126-trigger-click-on-input-when-label-is-clicked" title="Auslöser Klicken Sie auf Eingabe, wenn auf Beschriftung geklickt wird CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/7250426/trigger_click_on_input_when_label_is_clicked_css-tricks.png.webp" loading="lazy" alt="Auslöser Klicken Sie auf Eingabe, wenn auf Beschriftung geklickt wird CSS-Tricks" title="Auslöser Klicken Sie auf Eingabe, wenn auf Beschriftung geklickt wird CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8001126-trigger-click-on-input-when-label-is-clicked" title="Auslöser Klicken Sie auf Eingabe, wenn auf Beschriftung geklickt wird CSS-Tricks" rel="bookmark">Auslöser Klicken Sie auf Eingabe, wenn auf Beschriftung geklickt wird CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8002860-align-self" title="Selbst ausrichten - CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/8122876/align-self_css-tricks.png.webp" loading="lazy" alt="Selbst ausrichten - CSS-Tricks" title="Selbst ausrichten - CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8002860-align-self" title="Selbst ausrichten - CSS-Tricks" rel="bookmark">Selbst ausrichten - CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8002861-all" title="Alle - CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/8145203/all_css-tricks.png.webp" loading="lazy" alt="Alle - CSS-Tricks" title="Alle - CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8002861-all" title="Alle - CSS-Tricks" rel="bookmark">Alle - CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li>
		</ul>
	</div>

	<div class="widget widget-popular-posts">
		<h2 class="widget-title">Die besten Bewertungen für den Monat</h2>
		<ul class="post-list-small">
			<li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003026-scroll-snap-stop" title="Scroll-Snap-Stop - CSS-Tricks" rel="bookmark">Scroll-Snap-Stop - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003027-scroll-behavior" title="Bildlaufverhalten - CSS-Tricks" rel="bookmark">Bildlaufverhalten - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003028-scrollbar-color" title="Bildlaufleistenfarbe - CSS-Tricks" rel="bookmark">Bildlaufleistenfarbe - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003029-shape-image-threshold" title="Formbildschwelle - CSS-Tricks" rel="bookmark">Formbildschwelle - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003030-stroke" title="Schlaganfall - CSS-Tricks" rel="bookmark">Schlaganfall - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003031-speak" title="Sprechen - CSS-Tricks" rel="bookmark">Sprechen - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003032-scrollbar-width" title="Bildlaufleistenbreite - CSS-Tricks" rel="bookmark">Bildlaufleistenbreite - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003034-stroke-dasharray" title="Schlaganfall-dasharray - CSS-Tricks" rel="bookmark">Schlaganfall-dasharray - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003035-stroke-dashoffset" title="Strich-Dashoffset - CSS-Tricks" rel="bookmark">Strich-Dashoffset - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003036-shape-outside" title="Form außen - CSS-Tricks" rel="bookmark">Form außen - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003038-stroke-width" title="Strichbreite - CSS-Tricks" rel="bookmark">Strichbreite - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003040-table-layout" title="Tabellenlayout - CSS-Tricks" rel="bookmark">Tabellenlayout - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003041-stroke-linecap" title="Strichkappe - CSS-Tricks" rel="bookmark">Strichkappe - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003042-tab-size" title="Tab-Größe - CSS-Tricks" rel="bookmark">Tab-Größe - CSS-Tricks</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003043-text-align-last" title="Text-align-last - CSS-Tricks" rel="bookmark">Text-align-last - CSS-Tricks</a></h3>
					</div>
				</div>
			</li>
		</ul>
	</div>
	
<div id="container-5533149ee6411a5f99b370c693e87966"></div>	<div class="widget widget-popular-posts">
		<h2 class="widget-title">Top Artikel</h2>
		<ul class="post-list-small">
			<li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8003764-replacements-for-setinterval-using-requestanimationframe" title="Ersetzungen für setInterval mit requestAnimationFrame - CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/8639115/replacements_for_setinterval_using_requestanimationframe_css-tricks.png.webp" loading="lazy" alt="Ersetzungen für setInterval mit requestAnimationFrame - CSS-Tricks" title="Ersetzungen für setInterval mit requestAnimationFrame - CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003764-replacements-for-setinterval-using-requestanimationframe" title="Ersetzungen für setInterval mit requestAnimationFrame - CSS-Tricks" rel="bookmark">Ersetzungen für setInterval mit requestAnimationFrame - CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8003765-select-random-item-from-an-array" title="Wählen Sie Zufälliges Element aus einem Array - CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/2125305/select_random_item_from_an_array_css-tricks.png.webp" loading="lazy" alt="Wählen Sie Zufälliges Element aus einem Array - CSS-Tricks" title="Wählen Sie Zufälliges Element aus einem Array - CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003765-select-random-item-from-an-array" title="Wählen Sie Zufälliges Element aus einem Array - CSS-Tricks" rel="bookmark">Wählen Sie Zufälliges Element aus einem Array - CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li><li class="post-list-small__item">
				<div class="post-list-small__entry clearfix">
					<div class="post-list-small__img-holder">
						<div class="thumb-container thumb-100"><a href="/8003766-required-parameters-for-functions-in-javascript" title="Erforderliche Parameter für Funktionen in JavaScript - CSS-Tricks" rel="bookmark"><img src="https://cdn.css-code.org/8401366/required_parameters_for_functions_in_javascript_css-tricks.png.webp" loading="lazy" alt="Erforderliche Parameter für Funktionen in JavaScript - CSS-Tricks" title="Erforderliche Parameter für Funktionen in JavaScript - CSS-Tricks" class="post-list-small__img--rounded" style="width:88px;height:88px" /></a></div>
					</div>
					<div class="post-list-small__body">
						<h3 class="post-list-small__entry-title"><a href="/8003766-required-parameters-for-functions-in-javascript" title="Erforderliche Parameter für Funktionen in JavaScript - CSS-Tricks" rel="bookmark">Erforderliche Parameter für Funktionen in JavaScript - CSS-Tricks 2025</a></h3>
					</div>
				</div>
			</li>
		</ul>
	</div>
</aside>			</div>
		</div>
		
<footer class="footer footer--dark">
	<div class="container">
		<div class="footer__widgets">
			<div class="row">
				<div class="col-lg-4">
					<div class="widget">
						<h2 class="widget-title">Beliebte Beiträge</h2>
						<ul class="post-list-small">
							<li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003339-045-hot-link-modules" title="# 045: Hot Link-Module - CSS-Tricks" rel="bookmark"># 045: Hot Link-Module - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003340-043-responsive-izing-search" title="# 043: Responsive-izing-Suche - CSS-Tricks" rel="bookmark"># 043: Responsive-izing-Suche - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003341-046-flexible-sidebar-ads" title="# 046: Flexible Seitenleistenanzeigen - CSS-Tricks" rel="bookmark"># 046: Flexible Seitenleistenanzeigen - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003342-048-building-the-poll-module-part-2" title="# 048: Erstellen des Umfragemoduls, Teil 2 - CSS-Tricks" rel="bookmark"># 048: Erstellen des Umfragemoduls, Teil 2 - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003343-047-building-the-poll-module-part-1" title="# 047: Erstellen des Umfragemoduls, Teil 1 - CSS-Tricks" rel="bookmark"># 047: Erstellen des Umfragemoduls, Teil 1 - CSS-Tricks</a></h3>
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
				<div class="col-lg-4">
					<div class="widget">
						<h2 class="widget-title">Tipp Der Redaktion</h2>
						<ul class="post-list-small">
						<li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8226125-40-best-free-mp4-video-editor-2021" title="40+ Bester KOSTENLOSER MP4-Video-Editor (2021)" rel="bookmark">40+ Bester KOSTENLOSER MP4-Video-Editor (2021)</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8226126-11-best-free-drawing-courses-and-certification-2021-update" title="11 besten kostenlosen Zeichenkurse & Zertifizierung (2021 Update)" rel="bookmark">11 besten kostenlosen Zeichenkurse & Zertifizierung (2021 Update)</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8226128-80-best-autocad-courses-in-2021" title="80 besten AutoCAD-Kurse im Jahr 2021" rel="bookmark">80 besten AutoCAD-Kurse im Jahr 2021</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8226130-what-is-pmp-certification-cost-benefits" title="Was ist PMP? Zertifizierungskosten, Nutzen" rel="bookmark">Was ist PMP? Zertifizierungskosten, Nutzen</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8226131-project-management-methodologies-tutorial" title="Lernprogramm für Projektmanagementmethoden" rel="bookmark">Lernprogramm für Projektmanagementmethoden</a></h3>
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
				<div class="col-lg-4">
					<div class="widget">
						<h2 class="widget-title">Top Artikel</h2>
						<ul class="post-list-small">
						<li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003470-blurry-text" title="Verschwommener Text - CSS-Tricks" rel="bookmark">Verschwommener Text - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003472-bouncy-animated-loading-animation" title="Bouncy Animated Loading Animation - CSS-Tricks" rel="bookmark">Bouncy Animated Loading Animation - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003473-animated-grainy-texture" title="Animierte körnige Textur - CSS-Tricks" rel="bookmark">Animierte körnige Textur - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003474-center-div-with-dynamic-height" title="Center DIV mit dynamischer Höhe - CSS-Tricks" rel="bookmark">Center DIV mit dynamischer Höhe - CSS-Tricks</a></h3>
									</div>
								</div>
							</li><li class="post-list-small__item">
								<div>
									<div>
										<h3 class="post-list-small__entry-title"><a href="/8003475-browser-specific-hacks" title="Browserspezifische Hacks - CSS-Tricks" rel="bookmark">Browserspezifische Hacks - CSS-Tricks</a></h3>
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div>
			</div>
			<p>© Copyright de.css-code.org, 2025 April | 
				<a href="https://de.css-code.org/about-site" title="Über Site">Über Site</a> | 
				<a href="https://de.css-code.org/contacts" title="Kontakte">Kontakte</a> | 
				<a href="https://de.css-code.org/privacy-policy" title="Datenschutz-Bestimmungen">Datenschutz-Bestimmungen</a>.
			</p>
			
		</div>
	</div>
</footer>		
<link href="https://css-code.org/template/css/style.min.css" rel="preload" as="style" onload="this.onload=null;this.rel='stylesheet'" />	</body>
</html>