Skip to main content

JAVASCRIPT PROGRAMMING CONSTRUCTS




Most of the programming languages have a common set of programming constructs. JavaScript also provides a complete range of basic programming constructs.

JavaScript Conditional Statements

As in any other programming language conditional statements in JavaScript are used to perform different actions based on different conditions. While writing a code you may want to perform different actions for different decisions. For this JavaScript has following conditional statements:
1. If statement - use this statement if you want to execute some code only if a specified condition is true.
Syntax

if (condition)
{
/* code to be executed if condition is true*/
}

E.g. Using if statement



E.g.



Note: in case If is written in lowercase letters using uppercase letters (IF) will generate a JavaScript error!
2. if...else statement:- This statement is used if you want to execute some code if the condition is true and any another code if the condition is false.
Syntax:
if (condition)
{
// code executed if condition is true
}
else
{
// code executed if condition is not true
}
E.g. Displaying Greeting using if else construct

3. if...else if....else statement - use this statement if you want to select one of many blocks of code to be executed.
Syntax:
if (condition1)
{
//code to be executed if condition1 is true
}
else if (condition2)
{
//code to be executed if condition2 is true
}
else
{
//code to be executed if condition1 and condition2 are not true
}
E.g. if...else if....else statement


Note: While comparing variables you must always use two equals signs next to each other (==)!. In such case code executed only if the specified condition is true.
5. Switch statement – You can use Switch statement to select one of many blocks of code that is to be executed. With the Switch statement you can select from a number of alternatives.
Syntax:
switch(value)
{
Case 1:
//This code executed if first alternative is chosed
break;
Case 2;
//This code executed if second alternative is chosed
break;
default://used to take a default action
}
Note: You need to use break to come out of the Switch statement once selected case code is executed

Comments

Popular posts from this blog

Advantages and Disadvantages of EIS Advantages of EIS Easy for upper-level executives to use, extensive computer experience is not required in operations Provides timely delivery of company summary information Information that is provided is better understood Filters data for management Improves to tracking information Offers efficiency to decision makers Disadvantages of EIS System dependent Limited functionality, by design Information overload for some managers Benefits hard to quantify High implementation costs System may become slow, large, and hard to manage Need good internal processes for data management May lead to less reliable and less secure data

Inter-Organizational Value Chain

The value chain of   a company is part of over all value chain. The over all competitive advantage of an organization is not just dependent on the quality and efficiency of the company and quality of products but also upon the that of its suppliers and wholesalers and retailers it may use. The analysis of overall supply chain is called the value system. Different parts of the value chain 1.  Supplier     2.  Firm       3.   Channel 4 .   Buyer

Big-M Method and Two-Phase Method

Big-M Method The Big-M method of handling instances with artificial  variables is the “commonsense approach”. Essentially, the notion is to make the artificial variables, through their coefficients in the objective function, so costly or unprofitable that any feasible solution to the real problem would be preferred, unless the original instance possessed no feasible solutions at all. But this means that we need to assign, in the objective function, coefficients to the artificial variables that are either very small (maximization problem) or very large (minimization problem); whatever this value,let us call it Big M . In fact, this notion is an old trick in optimization in general; we  simply associate a penalty value with variables that we do not want to be part of an ultimate solution(unless such an outcome is unavoidable). Indeed, the penalty is so costly that unless any of the  respective variables' inclusion is warranted algorithmically, such variables will ...