Veda Bites are swipeable micro-lessons — each one teaches exactly one
idea. The bites below come from this kit — swipe through them in the app.
💡 Key Idea
JavaScript શું છે?
વેબની ભાષા, શીખો મૂળભૂત.
JavaScript (JS) એ high-level, interpreted programming language છે જેનો ઉપયોગ મુખ્યત્વે web pagesને *interactive* બનાવવા માટે થાય છે. તે HTML અને CSS સાથે મળીને કામ કરે છે. JS browserમાં ચાલે છે અને userના actionsને respond કરી શકે છે.
↳ JavaScript એ વેબ પરની સૌથી મહત્વપૂર્ણ scripting language છે.
📖 Definition
Variables: let, const, var
ડેટા સ્ટોર કરવાના ત્રણ રસ્તા.
JavaScriptમાં ડેટા સ્ટોર કરવા માટે variables વપરાય છે. ત્રણ મુખ્ય keywords છે: `let`, `const`, અને `var`. `let` block-scoped છે અને તેની value બદલી શકાય છે. `const` પણ block-scoped છે પણ તેની value reassign કરી શકાતી નથી. `var` function-scoped છે અને જૂની પદ્ધતિ છે.
↳ મોટાભાગે `let` અને `const` વાપરો, `var` ટાળો.
⭐ Important Fact
Data Types: Primitive vs Reference
ડેટાના પ્રકારો સમજો.
JavaScriptમાં primitive data types (String, Number, Boolean, null, undefined, Symbol, BigInt) અને reference data types (Object, Array, Function) હોય છે. Primitives by value સ્ટોર થાય છે, જ્યારે references by reference સ્ટોર થાય છે.
↳ Primitives immutable છે, objects mutable છે.
✏️ Example
typeof Operator
ડેટા type કેવી રીતે ચેક કરવો?
`typeof` operator કોઈપણ valueનો data type શોધવા માટે વપરાય છે. તે string return કરે છે.
↳ `typeof` data type ઓળખવા માટે ઉપયોગી છે, પણ `null` માટે સાવધાન રહો.
➗ Formula
Type Coercion
JavaScript આપોઆપ type બદલે છે.
Type coercion એટલે JavaScript દ્વારા એક data typeને બીજામાં આપોઆપ રૂપાંતરિત કરવું. ઉદાહરણ: `'5' - 3` → `2` (string numberમાં convert થાય છે).
↳ Type coercion ઉપયોગી છે પણ અણધાર્યા પરિણામો લાવી શકે છે.
⚠️ Common Mistake
== vs ===
સમાનતા ચેક કરવાની સાચી રીત.
`==` (loose equality) type coercion કરે છે, જ્યારે `===` (strict equality) type અને value બંને ચેક કરે છે. હંમેશા `===` વાપરવાની ભલામણ કરવામાં આવે છે.
↳ ભૂલો ટાળવા માટે `===` વાપરો.
💡 Key Idea
Functions: Declaration vs Expression
કોડને ફરીથી વાપરો, function બનાવો.
Functions JavaScriptમાં codeના reusable blocks છે. Function declaration: `function name() {}` hoisted થાય છે. Function expression: `const name = function() {}` hoisted થતું નથી. Arrow functions: `() => {}` concise syntax આપે છે.
↳ Arrow functions modern JavaScriptમાં પ્રિય છે.
⚙️ Process
Scope: Global vs Local
Variable ક્યાં ઉપલબ્ધ છે?
Scope એટલે variableની accessibilità. Global scopeમાં variable બધી જગ્યાએ access થાય છે. Local scope (function/block scope)માં variable ફક્ત તે blockની અંદર જ ઉપલબ્ધ છે. `let` અને `const` block-scoped છે.
↳ Variableની scope સમજવી bugs ટાળવા માટે જરૂરી છે.
⚖️ Comparison
null vs undefined
બંને 'કંઈ નહીં' દર્શાવે છે, પણ અલગ.
↳ `null` intentional છે, `undefined` unintentional.
✅ Best Practice
Naming Conventions
સારા નામ, સારો કોડ.
↳ Consistent naming code readability વધારે છે.
🎯 Exam Tip
Hoisting સમજો
Declaration ઉપર ખસે છે.
Hoisting એ JavaScriptની એક વર્તણૂક છે જેમાં variable અને function declarations તેમના scopeની ટોચ પર 'ખસેડાય' છે. ફક્ત declarations hoist થાય છે, initializations નહીં. `let` અને `const` hoisted છે પણ temporal dead zoneમાં હોય છે.
↳ Hoisting સમજવાથી અણધાર્યા errors ટાળી શકાય છે.
🧠 Memory Trick
Primitives યાદ રાખવાની ટ્રિક
7 primitives: S N B N U S B.
JavaScriptમાં 7 primitive types છે: String, Number, Boolean, Null, Undefined, Symbol, BigInt. ટ્રિક: "SNBNUSB".
↳ આ ટ્રિક primitives યાદ રાખવામાં મદદ કરશે.
🌍 Real World
Real-World: Form Validation
JavaScript વેબ ફોર્મ ચેક કરે છે.
વેબસાઇટ્સ પર form submit કરતા પહેલા JavaScript દ્વારા input ચેક કરવામાં આવે છે. ઉદાહરણ: email format સાચો છે કે નહીં, password length ઓછો છે કે નહીં. આ user experience સુધારે છે અને server પરનો ભાર ઘટાડે છે.
↳ JavaScript client-side validation માટે અનિવાર્ય છે.
🛠️ Application
Template Literals
Stringsને સરળ બનાવો.
Template literals backticks (`` ` ``) દ્વારા બનાવાય છે. તેમાં `${expression}` દ્વારા variables અને expressions embed કરી શકાય છે. Multiline strings પણ સરળતાથી બનાવી શકાય છે.
↳ Template literals string manipulationને વધુ સરળ બનાવે છે.
❓ Did You Know
JavaScriptનો જન્મ
10 દિવસમાં બનાવાયેલી ભાષા.
JavaScript 1995માં Brendan Eich દ્વારા માત્ર 10 દિવસમાં બનાવવામાં આવી હતી. શરૂઆતમાં તેનું નામ Mocha હતું, પછી LiveScript, અને અંતે JavaScript. આજે તે વિશ્વની સૌથી લોકપ્રિય programming languagesમાંની એક છે.
↳ JavaScriptનો ઇતિહાસ રસપ્રદ અને પ્રેરણાદાયક છે.
🚫 Warning
Semicolons: Optional પણ સાવધાન
ભૂલો ટાળવા semicolon વાપરો.
JavaScriptમાં semicolons (;) optional છે, પણ ક્યારેક તેને ન નાખવાથી Automatic Semicolon Insertion (ASI) અણધાર્યા પરિણામો લાવી શકે છે. ઉદાહરણ: return પછી નવી લાઇન પર value લખવાથી undefined return થાય છે.
↳ ભૂલો ટાળવા માટે semicolons નાખવાની આદત બનાવો.