PRIMITIVE HTML
PRIMITIVE HTML
▪ JavaScript has five primitive types: Number, String, Boolean, Undefined, and Null.
▪ Each primitive value has one of these types.
▪ JavaScript includes predefined objects that are closely related to the Number, String, and
Boolean types, named Number, String, and Boolean, respectively.
▪ These objects are called wrapper objects.
▪ Each contains a property that stores a value of the corresponding primitive type.
▪ The purpose of the wrapper objects is to provide properties and methods that are convenient
for use with values of the primitive types.
▪ The difference between primitives and objects is shown in the following example.
Javascript
4. Boolean: The boolean data type can accept only two values i.e. true and
false.
console.log("value of bool=" + bool);
5. Null: This data type can hold only one possible value that is null. The null in
JavaScript is a data type that is represented by only one value, the ‘null’ itself. A null value
means no value.
let x = null;
console.log("Value of x=" + x);
Operators
JavaScript has arithmetic, string, and logical operators. There are
both binary and unary operators. A binary operator requires two operands, one before
the operator and one after the operator:
operand1 operator operand2
For example, 3 + 4 or x * y
A unary operator requires a single operand, either before or after the operator:
operator operand
or
operand operator
For example x++ or ++x.
+= x += y x=x+y x = 15 Try
*= x *= y x=x*y x = 50 Try
: x: 45 size.x = 45 x = 45
Comparison Operators
Comparison operators are used in logical statements to determine equality or
difference between variables or values.
== equal to x == 8 false
== equal to x == 5 true
Logical Operators
Logical operators are used to determine the logic between variables or values.
Given that x = 6 and y = 3, the table below explains the logical operators:
Given that t1 = "Good ", t2 = "Morning", and t3 = "", the table below explains the operators:
Oper Example t1 t2 t3
Expressions
An expression is any valid set of literals, variables, operators, and expressions that
evaluates to a single value. The value may be a number, a string, or a logical value.
Conceptually, there are two types of expressions: those that assign a value to a
variable, and those that simply have a value. For example, the expression
x = 7
is an expression that assigns x the value 7. This expression itself evaluates to 7. Such
expressions use assignment operators. On the other hand, the expression
3 + 4
simply evaluates to 7; it does not perform an assignment. The operators used in such
expressions are referred to simply as operators.
The special keyword null denotes a null value. In contrast, variables that have not
been assigned a value are undefined, and cannot be used without a run-time error.
Conditional Expressions
A conditional expression can have one of two values based on a condition. The syntax
is
(condition) ? val1 : val2
If condition is true, the expression has the value of val1, Otherwise it has the value
of val2. You can use a conditional expression anywhere you would use a standard
expression.
For example,
status = (age >= 18) ? "adult" : "minor"
This statement assigns the value "adult" to the variable status if age is eighteen or
greater. Otherwise, it assigns the value "minor" to status.
The other operators are shorthand for standard arithmetic operations as follows:
x += y means x = x + y
x -= y means x = x - y
x *= y means x = x * y
x /= y means x = x / y
x %= y means x = x % y