← Back to TypeScript Course | Chapter 1: Introduction to TypeScript | Lesson 7 of 7

TypeScript का Playground

TypeScript Playground एक online environment है जहां आप local development environment install किए बिना TypeScript के साथ experiment कर सकते हैं। यह आपको TypeScript लिखने, compiler output देखने, और यह explore करने देता है कि अलग-अलग compiler options generated JavaScript को कैसे affect करते हैं।

Playground में TypeScript लिखना

Playground TypeScript code enter करने और zero setup के साथ instantly compiler का output देखने के लिए एक browser-based editor provide करता है। यह beginners के लिए खासतौर पर useful है क्योंकि experiments तुरंत try किए जा सकते हैं, एक local project बनाए या कुछ install किए बिना।

उदाहरण: Writing TypeScript in the Playground

typescript
// Paste into the online Playground - no setup required
let city: string = "Mumbai";
console.log(city);

JavaScript Output देखना

Playground की सबसे useful features में से एक एक side-by-side panel है जो exactly दिखाता है कि आपका TypeScript source plain JavaScript में कैसे transform होता है। यह concrete बनाता है कि type annotations एक development-time-only feature हैं, क्योंकि वे strip हो जाती हैं और emitted JavaScript में कभी नहीं दिखती।

उदाहरण: Viewing JavaScript Output

typescript
let count: number = 5;
console.log(count);
// Playground's right panel shows this compiled to: let count = 5; console.log(count);

Type Errors Test करना

Playground आपके type करते ही TypeScript compiler की diagnostics live दिखाता है, इसे intentionally incorrect types लिखकर type system के साथ experiment करने के लिए एक great जगह बनाते हुए।

Exactly देखना कि compiler कैसे और क्यों object करता है real intuition बनाता है कि type checker आपके code के बारे में कैसे reason करता है।

उदाहरण: Testing Type Errors

typescript
let age: number = 25;
// age = "twenty"; // Playground highlights this as a type error live
console.log(age);

Compiler Options के साथ Experiment करना

Playground target और strict जैसी compiler settings के साथ experiment करने के लिए controls expose करता है बिना कभी एक tsconfig.json file छुए। इन options को toggle करना और diagnostics और generated JavaScript दोनों को बदलते देखना आपको समझने में मदद करता है कि हर setting असल में क्या control करती है।

उदाहरण: Experimenting with Compiler Options

typescript
// Playground sidebar toggle: target = ES5, strict = true
let value: number = 10;
console.log(value);

Experiments से सीखना

क्योंकि आप code का एक छोटा टुकड़ा बदल सकते हैं और immediately compiler diagnostics और generated JavaScript दोनों को update होते देख सकते हैं, Playground सीखने के लिए एक unusually fast feedback loop है।

यह एक real project में commit करने से पहले unfamiliar TypeScript syntax test करने के लिए एक convenient जगह है।

उदाहरण: Learning Through Experiments

typescript
let x: number = 2;
let y: number = 3;
console.log(x + y);
// Change a type above and watch diagnostics/output update instantly
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Playground से ऐसा code run करने की उम्मीद करना जिसे files, npm packages या filesystem चाहिए, जब यह एक छोटा in-browser sandbox है।
  2. Compiler-options panel ignore करना और यह सोचना कि एक type error क्यों दिखता है (या गायब हो जाता है) जब strict toggle किया जाए।
  3. यह सोचना कि right-hand JavaScript output में अब भी आपकी type annotations हैं, जब वे remove कर दी गई हैं।
चैप्टर सारांश
  • TypeScript JavaScript का एक typed superset है जिसे आप tsc compiler से plain JavaScript में compile करते हैं।
  • Setting up में TypeScript install करना, एक पहला .ts program लिखना, और type errors early देखने के लिए इसे compile करना शामिल है।
  • एक tsconfig.json file compiler behavior control करती है, और TypeScript Playground आपको browser में experiment करने देता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.