Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)
Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 4 Min Lesezeit
0

Day 2: Understanding Variables and Data Types in JavaScript

↗ Quelle (dev.to)
🗣️ Stimme:




Introduction



Welcome to Day 2 of your JavaScript journey! Yesterday, we set up our development environment and wrote our first lines of JavaScript code. Today, we will dive into variables and data types, which are fundamental concepts in any programming language.






Variables



Variables are used to store data values that can be used and manipulated throughout your code. In JavaScript, you can declare variables using var, let, or const.



1. var



var is the traditional way to declare variables in JavaScript. Variables declared with var have function scope and are hoisted to the top of their scope.



Example:




CODE
var name = "Alice";
console.log(name); // Output: Alice






2. let



let was introduced in ES6 and provides block scope, which means the variable is only accessible within the block it was declared.



Example:




CODE
let age = 25;
if (true) {
let age = 30;
console.log(age); // Output: 30 (inside block)
}
console.log(age); // Output: 25 (outside block)






3. const



const is also block-scoped and is used to declare variables that cannot be reassigned. However, the contents of objects and arrays declared with const can be modified.



Example:




CODE
const city = "New York";
console.log(city); // Output: New York

const person = {
name: "Bob",
age: 30
};
person.age = 31; // Allowed
console.log(person.age); // Output: 31









Data Types



JavaScript has several data types, categorized into two main groups: primitive and non-primitive (objects).



Primitive Data Types:





  1. String: Used to represent textual data.




CODE
   let greeting = "Hello, World!";
console.log(greeting); // Output: Hello, World!








  1. Number: Represents both integer and floating-point numbers.




CODE
   let score = 100;
let price = 99.99;
console.log(score); // Output: 100
console.log(price); // Output: 99.99








  1. Boolean: Represents a logical value, either true or false.




CODE
   let isLoggedIn = true;
console.log(isLoggedIn); // Output: true








  1. Null: Represents an intentional absence of any value.




CODE
   let emptyValue = null;
console.log(emptyValue); // Output: null








  1. Undefined: Indicates that a variable has been declared but not assigned a value.




CODE
   let notAssigned;
console.log(notAssigned); // Output: undefined








  1. Symbol: A unique and immutable primitive value.




CODE
   let symbol = Symbol("unique");
console.log(symbol); // Output: Symbol(unique)






Non-Primitive Data Types:





  1. Object: Used to store collections of data and more complex entities.




CODE
   let person = {
name: "Charlie",
age: 28,
isStudent: true
};
console.log(person.name); // Output: Charlie








  1. Array: A special type of object used to store ordered collections of values.




CODE
   let fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits[1]); // Output: Banana









Type Conversion



JavaScript allows you to convert values from one type to another, either implicitly or explicitly.



Implicit Conversion:

JavaScript automatically converts types in certain operations.



Example:




CODE
let str = "123";
let num = 456;
console.log(str + num); // Output: "123456"






Explicit Conversion:

You can manually convert types using functions like String(), Number(), Boolean(), parseInt(), and parseFloat().



Example:




CODE
let str = "123";
let num = Number(str);
console.log(num); // Output: 123

let bool = "true";
console.log(Boolean(bool)); // Output: true

let floatStr = "123.45";
let intNum = parseInt(floatStr);
let floatNum = parseFloat(floatStr);
console.log(intNum); // Output: 123
console.log(floatNum); // Output: 123.45









Practice Activities





  1. Declare Variables:




    • Use var, let, and const to declare variables.

    • Experiment with variable scope by declaring variables inside and outside of functions and blocks.




  2. Work with Data Types:




    • Declare variables of different data types (string, number, boolean, null, undefined, object, array).

    • Log their values to the console.




  3. Convert Types:




    • Use implicit and explicit conversion methods to convert between different data types.

    • Practice converting strings to numbers and booleans.





Mini Project:

Create a simple script that takes user input (use prompt), converts it to a number, and logs the result of basic arithmetic operations.



Example:




CODE
let userInput = prompt("Enter a number:");
let number = parseInt(userInput);
console.log("Your number:", number);
console.log("Double:", number * 2);
console.log("Half:", number / 2);
console.log("Square:", number * number);









Summary



Today, we explored variables and data types in JavaScript. We learned how to declare variables using var, let, and const, and we discussed various data types including strings, numbers, booleans, null, undefined, objects, and arrays. We also practiced type conversion.



Stay tuned for Day 3, where we'll dive into operators and expressions in JavaScript!






Resources







Happy coding! If you have any questions or need further clarification, feel free to leave a comment below. Let's continue learning and growing together!



Follow me for more tutorials and tips on web development. Feel free to leave comments or questions below!






Follow and Subscribe:





  • Website:


  • YouTube:

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
Use custom web fonts in Google Sheets charts
2 Quellen
Introducing the new 1Password App for Google Chat
1 Quelle
Context-aware access controls are available for Gemini Enterprise in the Admin console
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 2: Understanding Variables and Data Types in JavaScript

Thematisch verwandte Begriffe: Understanding, Variables, Data, Types · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...