These days computer programs are being used in nearly each field, household, agriculture, medical, entertainment, defense, communication, and so forth. Listed are a few applications of computer programs: 01.MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., are examples of computer programs. 02.Computer programs are being used to develop graphics and special effects in movie making. 03.Computer programs are being used to perform Ultrasounds, X-Rays, and other medical examinations. 04.Computer programs are being used in our mobile phones for SMS, Chat, and voice communication.

JavaScript is the scripting language used to create dynamic content and interaction on web pages.
When JavaScript is used on a web page, it is done in the web browsers of the user's computer. In this case, JavaScript serves as the default language for clients.
JavaScript can be applied to both web browsers and servers. On servers you need a language supported by a JavaScript server. The server-side JavaScript executes on the server that allows you to access databases, file systems, etc.
We mainly use JavaScript to create
01. Websites
02. Web applications
03. Server-side applications using Node.js
In the following, you will learn the basics of the program and the backbone of some JavaScript implementation.



Prerequisites

  • Prior knowledge of HTML or HTML5 coding
  • A general idea on creating online applications
  • It is helpful to have some idea to object-oriented programming concepts
  • Tools: Notepad++, Sublime Text 3, Visual Studio Code
  • A Computer and Internet connection
  • Passion for learning!!!

Programming basics

Syntax

< ! -- The rules for how to write the language -- >

Input

< ! -- To feed some data into a program -- >

The element must have an ID < ! -- input type="text" id="bangladesh" value="lalmonirhat" -- >
And then you do this: var value = document.getElementById("text").value; Output
< ! -- To display some data on screen -- >
1.console.log() is used in debugging the code. console.log("Hello Alif"); 2.The alert() method displays an alert box over the current window with the specified message. alert("Hello Alif"); 3.document.write() is used when you want to print the content to the HTML document. document.write("Hello Alif"); Comment:

Comments can be used to explain why you added some selectors within your css file. To help others see your file, or to help you remember what we think over time. You can add comments that browsers will ignore as follows. You will see that it starts with / (forward slash) and over * (asterisks) and comments, then the closing marker goes back to the opening tag (asterisks) and / (forward slash).

/* */ Multi line comment
// One line comment

Declaring variables

< ! -- Variable represents the state of an object -- >
< ! -- Value is the reserved memory for variable -- >
< ! -- The equal sign is used to assign values to the variable -- >
< ! -- A variable name can't contain any spaces -- >
< ! -- A variable name can contain only letters, numbers, dollar signs, and underscores -- >
< ! -- Though a variable name can't be any of JavaScript's keywords, it can contain keywords. For example, userAlert and myVar are legal. -- >
< ! -- Capital letters are fine, but be careful. Variable names are case sensitive. A pen is not a Pen. If you assign the string "Rasel" to the variable pen, and then ask JavaScript for the value assigned to Pen, you'll come up empty -- > dataType variableName = value; var a; var rasel = 11;Ad Link Declaring many variables
< ! -- Variable is a name container for storing a single data value -- >
< ! -- The unique names are called identifiers. Such as, x and y, age, sum etc. -- >
< ! – The + character is used to add a variable to another variable -- > var x = 5, y = 6, z = 50;

Data types

< ! -- Data types are blocks or limited area for storing a set of name values -- > var age = 18; // number var name = "Rasel" ; // string var name = { first: "Rasel" , last: " Mia" }; // object var truth = false; // Boolean var sheet = [ "HTML" , " CSS" , " JS " ]; // array var a ; typeof a; // undefined var a = null; // value null

Operators

< ! -- Operator is a symbol -- >

Logical Operators: Logical AND ( && ) If both the operands are non zero then condition becomes true. Logical OR / Inclusive OR ( II ) If any of the two operands or both operands are non zero then conditions becomes true. Logical NOT ( ! ) If a condition is true then logical not operator will make false. Inverts the value of a Boolean. Bitwise Operator:
< ! -- It does work with only integer data -- > Binary AND ( & ) Results of AND is 1 when both bits are 0. Binary OR (|) Result of OR is 0 when both bit is 0. Binary NOT (~) Result of NOT is 0 when bit is 1 and 1 when bit is 0. Binary XOR (^) Result of XOR is 1 when two bits are different otherwise the result is 0. Either A is 1 or B is 1 then the output is 1 but when both A and B are 1 then output is 0. Arithmetic Operator: + (plus) - (minus) * (multiplication) / (division) % (module) Relational Operator: < (Less than) > (Greater than) <= (Less than or equal to) >= (Greater than or equal to) == (Equal) != (Not equal) Assignment Operator: = Assignment Operator += Plus Assignment Operator -= Minus Assignment Operator *= Multiple Assignment Operator /= Division Assignment Operator %= Module Assignment Operator Increment Operator: X++ ( Postfix Increment) Increment x by 1 after using its value. --X ( Prefix Decrement ) Decrement x by 1 before using its value. Special Operator: , Comma . Full stop ; Semicolon : Colon " " Quotation mark ! Exclamation mark / Slash \ Back slash - Under score $ Dollar sign % Percentage sign & Ampersand {} Second Bracket Conditional/Ternary Operator:
< ! -- Ternary operators are a shorthand if/else block. Works with three operator -- >
< ! -- Like if = else if : else -- > variable = condition? Expression1:Expression2;

Array

Arrays/2D and 3D Array/Multidimensional Arrays:
Arrays are similar to variables, but can hold more than one value.
Array of any size:
< ! -- [ ] 1st dimension -- > dataType[]arrayName = {coma separated values} Expects 3 values:
< ! -- [3]size 1 -- >
< ! -- [5][10][20] can store a total of (*5*10*20) = 1000 elements -- > dataType[]arrayName = new dataType[3]{command separated values}

String

A string is a letter, number, or any special mark, can contain any sequence of characters, visible or invisible, and characters may be repeated.
The number of characters on the string is called its length, and the "hello world" is 11 lengths consisting of 10 characters and one space.
Declaring a string: var nameOfString = " string value "; OR var nameOfString = new String(" string value" );

Conditional

if (if a condition is true) {} else ( if all conditions are false ) {} else if ( if a condition is false but different condition is true ) {} If statement: if ( if a condition is true then executes some code ) { Perform this action; } If else statement: if (if the condition in the if statement is false then execute some code ) { Perform this action; //compound statement } else //This is optional. It is needed , if all conditions are false { Perform this action; } Else if statement: if ( variables equal one value ) { Perform this action; } else if ( variable equals another value ) { Perform this action; } Switch statement:
< ! -- If you going to be doing a large number of tests, it makes sense to use a switch statement instead of nested ifs -- > switch(n) //n is variable or input. Only evaluates one variable. { Case 1: // if condition Code to be executed if n=1; //stament break; //exit the current scope
case 2: Code to be executed if n=2; break;
default : //else code to be executed if n doesn’t match any cases; break; }

Loop

< ! -- A loop is a command that repeats until a certain point is reached. According to the loop structure, the loop asks a question. If the answer requires action, it is done. The same question is asked again and again until no action is required. Each time a question is asked it is called an iteration. It uses the same lines of code many times in the system -- >

For loop:
< ! -- The for loop consisting of an initialization, an evaluation, and an increment.This looping process is best used when the number of iteration is known -- >
< ! -- in for loop we know when the loop will end -- > for ( before loop; condition; execute after loop) { What to do during the loop; } OR for ( initialization; condition; iteration) { What to do during the loop; } While loop:
< ! -- After execution, the test expression is evaluated again.If it is false the while loop terminates. -- >
< ! -- This is repeated as long as an expression is true -- >
while ( if the condition is true, staements inside the while loop are executed ) { statement; } Do While:
< ! -- The body of do while loop is executed at first, after that condition is checked -- >
< ! -- This repeats until an expression becomes false -- >
do { statement; }while ( condition );

Function

Function is a verb, behavior or action that is used to retrieve or manipulate data of an object.
< ! -- Function header = Access modifier-Return type-Method name-(Parameter type-Parameter name) -- >
< ! -- int is a actual parameter -- >
< ! -- x or y is a formal parameter -- >
< ! -- Name of method is an identifier -- > public int max ( int x, int y ) // Function header { Body of the method } OR
For JavaScript
< ! -- To declare a function, you use the function keyword, followed by the function name, a list of parameters, and the function body as follows -- > function functionName(parameters) { // function body // ... } Passing and returning values in method: Public int sum ( int num1, int num2 ) { int add = num1 + num2; //Passing values return add; //returning values } Calling a function:
< ! -- The value or variable are called argument -- > functionName ( arguments ); square(5); Library function / Built-in( Predefined ) function:
Those function which prototype holds various header file. length(); User defined function:
The parameters set by the user.