Fundamentals of JavaScript Code
Master Essential JavaScript Concepts Through Hands-On Practice
This tutorial builds foundational JavaScript skills through practical exercises. You'll work with alerts, variables, and data types - core concepts that appear in even the most complex applications.
Core JavaScript Concepts
JavaScript Methods
Learn about alert() and other JavaScript methods. Methods are like verbs in JavaScript - they perform actions and execute code.
Variables & Data Storage
Understand how to create and use variables to store information. Variables are containers that hold values for use throughout your code.
Strings vs Numbers
Discover the critical difference between text strings and numeric values. This distinction affects how JavaScript processes your data.
While you may not use alerts often on finished websites, they're invaluable for testing code when learning. Alerts provide immediate visual feedback to verify your JavaScript is working correctly.
Development Environment Setup
Launch Code Editor
Open Visual Studio Code, Sublime Text, or your preferred code editor to begin writing JavaScript code.
Open Project Files
Navigate to Desktop > Class Files > yourname-JavaScript jQuery Class > JavaScript-Fundamentals and open index.html.
Prepare HTML Canvas
Start with the blank HTML page provided - it serves as the perfect foundation for learning JavaScript syntax.
JavaScript is case-sensitive! Pay close attention to capitalization when writing variable names and method calls. myMessage and mymessage are treated as completely different variables.
Code Structure: Direct vs Variable Approach
| Feature | Direct Alert | Variable-Based Alert |
|---|---|---|
| Code Style | alert('Hello'); | var myMessage = 'Hello'; alert(myMessage); |
| Flexibility | Fixed message | Reusable variable |
| Best Practice | Quick testing | Production code |
Addition vs Concatenation
| Feature | Numbers | Strings |
|---|---|---|
| Code Example | 2 + 2 | '2' + '2' |
| Result | 4 | 22 |
| Operation | Mathematical addition | String concatenation |
JavaScript accepts both single and double quotes for strings. Single quotes are often preferred because they're faster to type - no Shift key required!
String Concatenation Process
Create Variables
Define separate variables for firstName and lastName with string values enclosed in quotes.
Remove Quotes in Alert
Use variable names without quotes so JavaScript reads the stored values, not literal text.
Add Space Character
Concatenate a space string ' ' between variables to properly format the output: firstName + ' ' + lastName
Key Takeaways
