Getting Started with JavaScript: Basics.

Getting Started with JavaScript: Basics.

  1. Install a code editor or IDE: There are many free and paid code editors and IDEs available for JavaScript development. Some popular choices are Visual Studio Code, Sublime Text, Atom, and WebStorm.

  2. Create a new JavaScript file: Once you have a code editor or IDE installed, you can create a new JavaScript file by selecting "New File" or "New Document" from the "File" menu. Give the file a meaningful name, such as "script.js".

  3. Write your code: In the new JavaScript file, you can start writing your code using the JavaScript language syntax.

  4. Save your file: Once you have written your code, save the file by selecting "Save" from the "File" menu. Make sure to save the file with a ".js" extension, such as "script.js".

  5. Link your JavaScript file to an HTML document: To use your JavaScript code on a web page, you need to link your JavaScript file to an HTML document using a script tag. For example:

     <!DOCTYPE html>
     <html>
     <head>
         <title>My Web Page</title>
         <script src="script.js"></script>
     </head>
     <body>
         <!-- Your HTML content here -->
     </body>
     </html>
    

We can use a <script> tag to add JavaScript code to a page.

The script has two attributes type and language. But the type and language attributes are not required.

A script in an external file can be inserted with the <script> tag example below.

<script src"script.js"> </script>

If src is set the script content is ignored.

<script src="file.js">
alert(Hello world); //The content is ignored. because src is set.
</script>

We must choose either an external<script src=" "> </script> or regular <script> </script> with code. like this

Example

//This code is exapmle of external javascript.

<script src="file.js> </script>
//This code is example of regular jS
<script> alert(1);  </script>

Statement

Statements are syntax constructs and command the perform a particular action. The syntax is a set of rules that determine how words are organized to form sentences in a language.

Example of Statement

alert('Hello Word!') // result is Hello Word

Semicolons

A semicolon may be omitted in most cases when a line break exists. Semicolon in JavaScript is a special symbol that is used to mark the end of a statement. It is like a full stop at the end of a sentence that tells the computer where the statement ends.

alert('Hello');  //result Hello
alert('Hello Word'); // result Hello Word

Another Example :

alert('Hello')  //result Hello
alert('Hello Word') // result Hello Word

The code is also working without a semicolon and still does not give the error. Why because javascript interprets the line break as an "implicit" Semicolon. This is called an automatic semicolon insertion.

I recommend and encourage you to put semicolons between statements even if they are separated by a new line. and this is good practice for your javascript learning journey.

Comment

Comments are pieces of text that are used to explain code to human readers. They are ignored by the computer when the code is executed, so they don't affect the behavior of the program. Comments are used to provide context and explanation for code, especially for other developers who may need to understand and modify the code in the future.

There are two types of comments.

1. One-line comment

2. Multi-line comment

//This is single line comment.

Single-line comments start with double forward slashes (//).

/*This is 
a multi line
comment */

Multiline comments start with a forward slash and asterisk /* and end with an asterisk and forward slash */.

Thank you.