Babel और SWC: JavaScript Transpilation और Build Speed कोर्स के 11 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।
मॉड्यूल 10: Interview Prep और Cheat Sheet
1. Babel का प्राथमिक उद्देश्य क्या है?
- JavaScript फ़ाइलों को minify और compress करना
- Multiple फ़ाइलों को एक में bundle करना
- पुराने browsers के लिए आधुनिक JavaScript को ES5-compatible syntax में convert करना
- npm packages संभालने के लिए
जवाब देखें
जवाब: पुराने browsers के लिए आधुनिक JavaScript को ES5-compatible syntax में convert करना
Babel आधुनिक JavaScript को compatible पुरानी syntax में transpile करता है। Minification और bundling अलग concerns हैं जो अन्य tools द्वारा संभाले जाते हैं।
पाठ: Common Interview Questions
2. SWC Babel से तेज क्यों है?
- SWC बड़ी फ़ाइलों के transpilation को skip करता है
- SWC JSX या TypeScript को transpile नहीं करता
- SWC सभी comments हटा देता है
- SWC को Rust में लिखा गया है और native code में compiled है, जबकि Babel interpreted JavaScript है
जवाब देखें
जवाब: SWC को Rust में लिखा गया है और native code में compiled है, जबकि Babel interpreted JavaScript है
SWC का Rust implementation बहुत बड़े performance gains को enable करता है। Compiled native code CPU-intensive parsing और AST transformation के लिए interpreted JavaScript से बहुत तेज है।
पाठ: Common Interview Questions
3. क्या Babel runtime features को add कर सकता है जो target browser में exist नहीं करते?
- नहीं, Babel केवल syntax को transpile कर सकता है; runtime features को polyfills की जरूरत है
- हाँ, हमेशा
- हाँ, लेकिन केवल Promise और Array methods के लिए
- केवल Chrome में
जवाब देखें
जवाब: नहीं, Babel केवल syntax को transpile कर सकता है; runtime features को polyfills की जरूरत है
Babel syntax को transpile करता है लेकिन functions को नहीं बना सकता जो exist नहीं करते। `Promise.all()` या `Array.prototype.includes()` जैसी runtime features के लिए, core-js जैसे polyfills का उपयोग करें।
पाठ: Common Interview Questions
4. Babel का मुख्य उद्देश्य क्या है?
- Minify code
- Bundle files
- Convert modern JavaScript into compatible code
- Run tests
जवाब देखें
जवाब: Convert modern JavaScript into compatible code
यह आपके target environments के लिए syntax बदलता है।
पाठ: Quick Reference और Cheat Sheet
5. SWC, Babel से तेज़ क्यों है?
- It skips JSX
- It caches nothing
- It uses fewer plugins only
- It is written in Rust and compiled to native code
जवाब देखें
जवाब: It is written in Rust and compiled to native code
Native code और parallelism इसे तेज़ करते हैं।
पाठ: Quick Reference और Cheat Sheet
6. क्या Babel और SWC TypeScript को type-check करते हैं?
- No, they only strip types
- Yes, fully
- Only in production
- Only with plugins
जवाब देखें
जवाब: No, they only strip types
Type checking के लिए tsc --noEmit चलाएँ।
पाठ: Quick Reference और Cheat Sheet
7. @babel/preset-env क्या देखकर तय करता है कि क्या transpile करना है?
- File size
- Your browser or Node targets
- Git history
- Package name
जवाब देखें
जवाब: Your browser or Node targets
Targets browserslist या targets option से आते हैं।
पाठ: Quick Reference और Cheat Sheet
8. Polyfills क्या जोड़ते हैं?
- New syntax rules
- Type checking
- Missing runtime features such as Promise
- Minification
जवाब देखें
जवाब: Missing runtime features such as Promise
Syntax transforms runtime APIs नहीं जोड़ सकते।
पाठ: Quick Reference और Cheat Sheet
9. Automatic JSX runtime किसकी जरूरत हटाता है?
- Writing JSX
- Using components
- Using hooks
- Importing React in every file
जवाब देखें
जवाब: Importing React in every file
Compiler react/jsx-runtime से jsx() inject करता है।
पाठ: Quick Reference और Cheat Sheet
10. कौन-सा tool variable names और whitespace compress करता है?
- A minifier such as Terser
- Babel
- Prettier
- tsc
जवाब देखें
जवाब: A minifier such as Terser
Transpilation और minification अलग चरण हैं।
पाठ: Quick Reference और Cheat Sheet
11. Babel plugin code कैसे बदलता है?
- By editing text with regex
- By visiting and modifying the AST
- By running the code
- By downloading packages
जवाब देखें
जवाब: By visiting and modifying the AST
Plugins syntax tree में घूमते हैं।
पाठ: Quick Reference और Cheat Sheet