Do you want to start programming but don't know where to start?
JavaScript is a great programming language for beginners because it has simple syntax, is easy to read, and is used in a wide range of fields.
In this article, we will explain the basics of JavaScript, with actual code examples. We will also introduce how to set up the environment and some key points to keep in mind when learning.
If you are looking to start programming or are interested in JavaScript, please refer to this article.
What is JavaScript?
Characteristics of JavaScript
• Simple grammarThe code is easy to read and understand, even for beginners.
• Extensive library: Can be used in a variety of fields, including web development, game development, and mobile app development.
• Large community: There is a wealth of information, learning materials and support available.
Examples of using JavaScript
• Web Development: Used to create dynamic web pages and improve the user interface.
• Game Development: Used for developing browser-based and mobile games.
• Mobile App Development: Develop cross-platform apps using frameworks such as React Native.
JavaScript environment setup
Run in browser
JavaScript can be easily executed on a browser without any special environment.
1. Create an HTML file like the one below in any text editor.
1 2 3 4 5 6 7 8 9 10 11 | <! DOCTYPE html> < html > < head > < title >JavaScript Test</ title > </ head > < body > < script > alert('Hello, JavaScript!'); </ script > </ body > </ html > |
2. Save the file and open it in a browser, you will see an alert.
Use the online editor
Our online editor allows you to learn JavaScript without installation.
• PlayCodeYou can write code in your browser and see the results immediately.
• JSFiddle: You can edit and run HTML, CSS, and JavaScript simultaneously.
Basic JavaScript Syntax
Variables and Data Types
In JavaScript, you work with data by assigning values to variables.
1 | let message = "Hello, JavaScript!" ; let number = 42; let isActive = true ; |
• String: Enclose in double or single quotes.
• Number: Write integers and decimals as they are.
• Logical valuesUse true or false.
Conditional branching
Processing can be branched according to conditions.
1 | let age = 18; if (age >= 18) { console.log( "I'm an adult." ); } else { console.log( "I'm underage." ); } |
Iteration
To repeat the same process, use the for or while statement.
1 | for ( let i = 0; i < 5; i++) { console.log(i); } |
Let's actually write some code
Following is a simple program which takes input from the user and displays a greeting.
1 | let name = prompt( "What is your name?" ); alert(`Hello ${name}!`); |
When this code is run, it prompts the user for their name and displays a greeting.
Key points for studying
• Set small goals: Let's start with a simple program, such as one that displays "Hello, World!".
• Get your hands dirtyWriting code helps you understand it better.
• Don't be afraid to make errors: Errors are learning opportunities.
• Leverage the community: Exchange information on Q&A sites and forums.
summary
JavaScript is an easy-to-learn and highly practical programming language for beginners. By understanding the basic grammar and actually writing code, you can steadily acquire skills.
Use this article as a reference to get started on learning JavaScript. Continuous learning and practice will help you improve your programming skills.