JavaScript Comments, Identifiers, Keywords, Statements, Expression

In this tutorial, you will learn javascript syntax with the following:

  • JS Case-Sensitive
  • Identifiers
  • Comments
  • Statements
  • Expressions
  • Keywords

JS Case-Sensitive

In JavaScript each thing like variables or identifiersfunction names, class names and operators are case-sensitive. This means that vol and Vol are two different variables in js.

For e.g. you cannot use  catch for the function name, because it is a reserved keyword in js. However, Catch is a valid function name.

Example 1: case-sensitive in js

<script>
function Catch() {
   document.write("Hello, My Coding Ground!");
}
Catch();
</script>

Identifiers

As the name suggests, An identifier is the name of a variable, function, parameter, and class in js.

Rules of writing an identifier:

  • The first character must be a letter (a-z, or A-Z), an underscore(_), or a dollar sign ($).
  • The other characters can be letters (a-z, A-Z), numbers (0-9), underscores (_), and dollar signs ($).

Note that the letter in this context is not limited to the ASCII character but may include extended ASCII or Unicode though it is not recommended.

Use the camel case for writing the identifiers because it’s is very good practice. Camel case means that the first letter of lowercase and each additional word starts with a capital letter when writing identifiers in js.

Example 1: Valid Identifiers js

counter
inArray
beginWith
redirectPage

Comments

In any programming languages, comments are very good practice. Because it make readable your codes.

JavaScript supports both single-line and block comments.

A single-line comment starts with two forward-slash characters (//).

Example 1: single line comment in js

// this is a single-line comment

A block comment starts with a forward slash and asterisk (/*) and ends with the opposite (*/) .

Example 2: Multi line comment in js

/*
* This is a block comment that can
* span multiple lines
*/

It is a good practice to use an asterisk to begin the comment line for readability purposes.

Statements

In javascript statements, you can use a semicolon to end a statement. It means semicolon will make your code more readable and helps you avoid many problems that you may encounter.

Example 1: JS Statement

See the following example for statement:

var a = 10;
var b = 20;

You can use a code block that begins with a left curly brace ({) and ends with the right curly brace (}) to combine multiple statements as follows:

if( a > b) {
   console.log('a is greater than b');
   return 1;
}

Expressions

In js, an expression is a piece of code that evaluates to a value.

Example 1: Expression in js

a = 2 + 5;

The above expression returns 7 so it is a valid expression.

Suppose you have two variables a and b and want to add both using the + operator.

See the following example:

a = 5;
b = 10;
c = a + b;

Keywords

Many programming languages have reserved keywords. JavaScript also provides a list of keywords, which you have used according to your requirements. And You cannot use the keywords as the identifiers.

In JS, Each keyword has a specific purpose to use.

The following list of JavaScript keywords:

breakexportsuper
caseextendsswitch
catchfinallytypeof
classforthis
constfunctionthrow
continueiftry
debuggerimportvar
defaultinvoid
deleteinstanceofwhile
donewwith
elsereturnyield

Conclusion

In this tutorial, you have learned JavaScript syntax including naming an identifier, constructing statements, and making comments in code.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

One reply to JavaScript Comments, Identifiers, Keywords, Statements, Expression

  1. Thanks a lot for this course, I’ve been programming in the early 90’s and trying to start again with web development, found your courses very clear and easy to follow. Again thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *