Skip to main content

JavaScript Basic

In this section mentioning all basic information about Javascript comment, variable, control statement and function. Which is normally used in javascript program.


In javascript comment are used to describe the code explanation and short description. All line which are commented by programmer, that lines are ignored at runtime. That means this commented line of code are not execute.

//Single line comment
	Multiline Line

There are two type of comment are support in javascript. single line comment and multi line comment. Programmer can use both comments in single source code file. Because both are useful.

Single line comment

Single line comment are used to describe short note in one line. That is start with // double forward slash.

Multi line comment

Multiline comment can be used to describe long description of code. that are define by /* and end with */.


variable is an identifier which are capable to store values or reference of instance variables (objects). Variable in javascript can be defined by using let or var keywords.

let variableName = value;
var varibaleNames = value;

Value of variable is an optional parameter. And define the name of variable is similar, to modern programming language. Name of variable should be start of character (a to z or A to Z) , (_) underscore or ($) dollar sign.

//define variable
let employeeSalary = 100000;

let $name = "Admin"; //assign string value

console.log("Name : ",$name);
console.log("Salary : ",employeeSalary);
Name :  Admin
Salary :  100000

Here console.log() method are display the message on browser console. This method are normally use when you are run javascript code using node JS. If you are test javascript code result in web browser then you can also use alter() method. This method are display message in popup to browser window.

Javascript variable are not based particular data type. variable value can be modified by any data type values.

let record ="Image";
console.log("record  : ",record);

//update variable value by number
record = 10;
console.log("record  : ",record);

record = 10.53;
console.log("record  : ",record);

//update variable value by boolean value
record = true;
console.log("record  : ",record);
record  :  Image
record  :  10
record  :  10.53
record  :  true


Function are implement a pattern. That can be contains group of instruction and statements which are used to solve particular task. This is also know as method, subrutine. The main advantage of function are it will be define once. And that is can be used in so many times of during run time. That is very effective mechanism that are provide reusability of code.

function keyword are used to define a javascript function then followed by the name of function. inside the parentheses () define parameter list (function parameters). After that using of {} curly braces define the body of method.

//Method without parameter value
function message(){
	//Define function instruction here
//Method with parameter values
//value and info is parameter
function test(value,info){
	//Define function instruction here
//function with returning values
function salary(id){
	return 1000000;

Function parameter : When function are not accept any argument then function parameter list are optional. If method are accepted parameter value then that is mentioned within the parenthesis. When function are accept more than one parameter values in this situation this is separated comma operator.

Function calling : The name of function and its parameter values are execute particular function which is define by programmer.

//Define a function
// name : message
// parms : info
function message(info){
	//method statement

//function calling
message("Hello Programmer");

message("Hello Coder");
Hello Programmer
Hello Coder

Function return statement : This statement are return result of function where is this function call.

function sum(num1,num2){

	return num1+num2;

console.log(sum(1,2)); //3
let result = sum(3,4);
console.log(result);  //7

console.log(result+sum(5,6)); //18


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment