Exploring TypeScript Basics: Variables, Naming, and Core Data Types - TypeScript Tutorial

 👋 Hello Learners! Welcome to the exciting world of TypeScript! 🚀 Whether you're just starting your coding journey or looking to expand your skills, you've come to the right place. Let's dive into the basics of TypeScript, focusing on variables and core data types. If you're new here or haven't set up your TypeScript environment yet, don't worry! Take a quick detour and read this article to get everything ready before continuing.





Watch Video:



Understanding Variables: 🤔

So, what exactly is a variable? Well, think of it as a labeled storage container for holding information in your program. It's like a box that can store different types of things - numbers, words, or even more complex data.


Naming Your Variables: 🏷️

Now, let's talk about naming your variables. It's like giving your storage box a name so you can easily find it later. Some simple rules:

  • Start with a letter (or underscore _)
  • Follow with letters, numbers, or underscores
  • Be descriptive but keep it short and sweet


Example Variables in JavaScript and TypeScript : 💻

Let's see this in action! Here's a quick example in JavaScript:

javascript

let myNumber = 42;
let greeting = "Hello, World!";

And in TypeScript, where we add a bit more structure:

typescript

let myNumber: number = 42;
let greeting: string = "Hello, World!";


Type Inference in TypeScript: 🕵️

One cool thing about TypeScript is type inference. This means that TypeScript can automatically figure out the type of your variable based on its initial value. So, you don't always have to explicitly mention the type.


let automaticTypeInference = "I'm a string!";


Core Data Types in TypeScript: 📦

Now, let's talk about some core data types in TypeScript:

  • number: For all numeric values. (Described in video)
  • string: For sequences of characters (text). (Described in video)
  • boolean: For true or false values. (Described in video)
  • array: For storing lists of values. (In Next video)
  • object: For more complex structures. (In Next video)


Examples of Core Data Types: 

let myNumber: number = 42;
let myText: string = "Hello, TypeScript!";
let isLearning: boolean = true;
let myArray: number[] = [1, 2, 3, 4, 5];
let myObject: { name: string, age: number } = { name: "John", age: 25 };

There you go, learners! 🚀 Variables and core data types are the building blocks of TypeScript. Remember, coding is like solving puzzles – keep practicing and enjoy the journey! If you have any questions, feel free to ask. 

If you wants to learn typescript in very easy way please save this playlist   (TypeScript For Beginners) and learn typescript!

Thanks for reading!

1 Comments

Previous Post Next Post