Code Structure Of JavaScript | Fundamentals of JavaScript Programming Language | Part — 1

Ashraf uddin
5 min readJul 9, 2021

--

What is JavaScript Programming Language?

JavaScript is among the most powerful and flexible programming languages that allows you to implement complex features on a website, such as dynamic elements or interactivity which is used by several websites for scripting the webpages and It is designed for creating network-centric applications.

Code Structure Of JavaScript (js) :

Writing well-structured code takes proper thinking, understanding of design patterns, and experience.

Here is a list of some of the fundamentals of JavaScript that you will learn about in this tutorial:

  • JavaScript Statements
  • JavaScript Semicolons
  • JavaScript Whitespaces
  • JavaScript Parenthesis
  • JavaScript Identifiers
  • JavaScript Indentation
  • JavaScript Reserved Keyword
  • JavaScript Case Sensitive
  • JavaScript Comments
  • JavaScript Camel Case

Here is a list of some of the fundamentals of JavaScript that you will learn about in next tutorial of Part — 2 :

  • JavaScript Syntax
  • JavaScript Values
  • JavaScript Literals
  • JavaScript Expression
  • JavaScript Variables
  • JavaScript Operators
  • JavaScript Character Set
  • JavaScript Data Types
  • JavaScript Code Blocks
  • JavaScript Line Length and Line Breaks

JavaScript is made up of a series of statements and semi-colons and a JavaScript program is a list of programming statements. JavaScript statements are the commands to tell the browser to what action to perform which are used to perform different actions based on different conditions.

A statement can set a variable equal to a value. A statement can also be a function call, i.e. document.write(). Statements define what the script will do and how it will be done.

Types of Statements in JavaScript (js):

We will provide a brief overview of each of the categories and cover them in greater detail later in the tutorial. There are five types of statements in javascript (js) :

  1. Conditional Statements
  2. Loop Statements
  3. Object Manipulation Statements
  4. Comment Statements
  5. Exception Handling Statements
let numOne, numTwo, sum; // Statement 1 numOne = 5; // Statement 2 numTwo = 6; // Statement 3 sum = numOne + numTwo; // Statement 4

2. Semicolons (;) in JavaScript (js):

Semicolons (;) separate JavaScript statements which are the equivalent of a full stop and it is used to terminate a statement.

Semi-colons are not compulsory because t he JavaScript or js parser will automatically add a semicolon during the parsing of the source code but using semicolons are highly recommended. Semicolons are used at end of the statements. When separated by semicolons, multiple statements on one line are allowed.

// when single statementslet a, b, c; a = 5; b = 6; c = a + b;// when multiple statements in one line

3. Whitespace in JavaScript (js):

A whitespace character is an empty space (without any visual representation) on screen. Whitespace in JavaScript consists of spaces, tabs, and newlines (pressing ENTER on the keyboard).

JavaScript ignores multiple spaces and free to format and indent programs in a neat and consistent way that makes the code easy to read and understand.

let person = "Best JavaScript Tutorials"; let person="Best JavaScript Tutorials";

A good practice is to put spaces around operators ( = + — * / ):

4. Parenthesis in JavaScript (js):

In JavaScript we only write a value in the parentheses if we need to process that value and it is used for grouping expressions. For keywords such as if, switch, and for, spaces are usually added before and after the parentheses.

// An example of if statement syntax if () { } // Check math equation and print a string to the console if (4 < 5) { console.log(“4 is less than 5.”); } // An example of for loop syntax for () { } // Iterate 10 times, printing out each iteration number to the console for (let i = 0; i <= 10; i++) { console.log(i); }

5. Identifiers in JavaScript (js):

Identifier is a sequence of characters; which help us to identify specific part of a program and The name of a variable, function, or property is known as an identifier in JavaScript.

Rules for Naming JavaScript Identifiers:

1. Identifiers should be meaningful.

2. Keywords should never be used as identifiers.

3. The first character can be an alphabet, underscore or dollar character.

4. The first character should not be a number.

5. All succeeding characters can be alphabets, a digits, or underscores.

6. No special characters are allowed except an underscore or dollar.

i my_variable_name v13 _dummy $str

Programmer uses newlines and indentation because of writing javascript program on a single line would quickly become very difficult to read and maintain.

There is no set standard for JavaScript code indentation . 4 spaces seems to be popular. Avoid using Tabs because Tabs may cause erratic behavior.

7. Reserved Keyword in JavaScript (js):

Keywords are words in the JavaScript language that have a built-in functionality and cannot use to indicate variable labels or function names such as ,, for, and . There are a total of 63 keywords that JavaScript provides to programmers.

var var = "Reserve Keywords can not use as variable name";SyntaxError: Unexpected token (1:4)

8. JavaScript is Case-sensitive:

The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters is known as a case-sensitive language. JavaScript is also a case-sensitive language.

9. Comments in JavaScript (js):

Comments which describe what the code does and why and can be put into any place of a script which is ignored by the JavaScript engine i.e. embedded in the browser. JavaScript supports both C-style and C++-style comments.

There are two types of comments in JavaScript:

  • One-line comments start with two forward slash characters //
  • Multiline comments start with a forward slash and an asterisk /* and end with an asterisk and a forward slash */
/* An example with two messages. This is a multiline comment in javascript */// this is a single line comment in javascript

10. Camel Case in JavaScript (js):

Camel case is the practice of writing phrases without spaces or punctuation which is a naming convention in which the first letter of each word in a compound word and an initial lowercase or uppercase letter, with each remaining word element beginning with an uppercase letter.

Alternatively known as bicapitalisation, bicapitalization, InterCaps, medial capitals, and Pascal case,

first-name, last-name, master-card, inter-city.

Hyphens are not allowed in JavaScript. They are reserved for subtractions.

first_name, last_name, master_card, inter_city.

Upper Camel Case (Pascal Case):

FirstName, LastName, MasterCard, InterCity.

JavaScript programmers tend to use camel case that starts with a lowercase letter:

firstName, lastName, masterCard, interCity.

Originally published at https://www.codeshikhi.com.

--

--

No responses yet