Skip to main content

Conditional Operator




Conditional Operator
JavaScript supports conditional expression operator. They are? and :. These operators are ternary operators as they require three operands , a condition to be evaluated and the alternatives that need to be returned. The return value is based on the condition as it can be true or false.

Syntax:

variablename=(condition)?value1:value2

E.g.
result=(percentage==50)?"Pass":"Fail";

In the above example if the variable percentage has the value 50, then the variable result will be assigned the value “Pass” else it will be assigned "False".

6. Using + Operator with Strings

The + operator can be used to add string variables or text values together. In case operands are number + operator performs addition. In case operands are strings it is used to concatenate them.

E.g. Concatenating two Strings

t1="Welcome";
t2="India";
t3=t1+t2;

After the execution of the statements above, the variable t3 will contain the string “Welcome India”.


With + operator it is possible to concatenate two or more strings. You can even insert spaces and concatenate a string with a number.

E.g. To add a space between the two strings you can insert a space into one of the strings:

t1="Welcome";
t2="India";
t3=t1+” “ + t2;

After the execution of the statements above, the variable t3 contains string
"Welcome India

Note: If you add a number and a string, the result will be a string.

Check Your Progress

1. What do you understand by a block of code in JavaScript?
2 What are different data types available in JavaScript?
3. What are the different kinds of comments available in
JavaScript?
4. Give the output of the following code;
w=4;
y=++w;
z=w++;
document.write(w);
document.write(y);
document.write(z);
5. What is the use of conditional operator?

Comments

Popular posts from this blog

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
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

System Analysis and Design (SAD)

Introduction to System Analysis and Design (SAD) System are created to solve Problems. One can think of the systemsapproch as an organised way of dealing with a problem. In this dynamic world , the subject system analysis and design, mainly deals with the software development activities. This post include:- What is System? What are diffrent Phases of System Development Life Cycle? What are the component of system analysis? What are the component of system designing? What is System? A collection of components that work together to realize some objectives forms a system. Basically there are three major components in every system, namely input, processing and output. In a system the different components are connected with each other and they are interdependent. For example, human body represents a complete natural system. We are also bound by many national systems such as political system, economic system, educational system and so forth. The objective of the system demands tha...