Primitive types String, Number, Boolean, Null, Undefined, Symbol, BigInt

Primitive types: String, Number, Boolean, Null, Undefined, Symbol, BigInt

In JavaScript programming, primitive data types indicate the most basic or fundamental JavaScript data types that are not modifiable in the JavaScript program, which cannot be changed directly. These are the default JavaScript program simple data type format, and these are not any array or object data types where primitive data types hold a single value in JavaScript program.

Primitive types String Number Boolean

So, let’s get to know the Primitive types String Number Boolean types in JavaScript programming better.

String Data Type.

In JavaScript program, string data type is represented in single quotation marks (‘), or double quotation marks (“), or backticks (`) in the order of number of string characters enclosed. JavaScript programmers can declare string data type variables with single and double quotes in the program.

Characteristics of String Data Type.

  • In JavaScript program, string data type is immutable, it means once string data type is created, programmers cannot modify it directly.
  • In JavaScript program, string variable data type is combined using + operator.

Simple String and Combined String Example in JavaScript.

let Message = “Hi, Vanhelpsu!”;

console.log(Message); // Result is – Hi, Vanhelpsu!

let course = ‘Javascript’;

let text = “Welcome to , ” + course + “!”;

console.log(text); // Result is – Welcome to , javascript!

In this program, you can apply template literals (backticks) for string interpolation if needed:

let info = ‘Great’;

let value = `world is, ${info}!`;

console.log(value); // Result is – world is, great

JavaScript Number Data Type.

Number data type in JavaScript program represents numeric integer value, where you can process and store both integer and floating-point numbers in number data type in JavaScript program.

Features of JavaScript Number Data Type.

  • Number data type is treated in only one way in any JavaScript program, which shows no difference between integer and float numeric values ​​in numbers value in the current program.
  • Infinity and NaN (Not a Number) are special program value numeric values ​​in JavaScript program.
  • In any JavaScript program, numbers are stored in 64-bit floating point format (IEEE 754).

Example of numeric data type in JavaScript program.

let p = 11;  // p declare Integer variable

let pi = 22/7;  // Floating-point number variable

let product = 2 * 2;  // multiply both numbers 4

console.log(p);  // result is -11

console.log(pi);  // result is -3.14

console.log(product);  // result is – 4

let infinityvalue = 10 / 0;  // declare Infinity variable

console.log(infinityvalue);  // result is – Infinity

let nanvalue = 0 / 0;  // NaN variable declare

console.log(nanvalue);  // result is – NaN

Boolean data type in JavaScript.

In JavaScript program, Boolean data type represents a logical unit, usually Boolean data type can hold one of two values, which can be in the form of true or false value.

Characteristics of JavaScript Boolean data type.

  • Boolean data type is useful for controlling the flow of JavaScript program, for example, in conditional logic like if statement.
  • In JavaScript program, Boolean data type often results in comparison and logic operations.

Example of JavaScript Boolean data type.

let isp = true;

let isq = false;

console.log(isp);  // result is – true

console.log(isq);  // result is – false

let isvalue = 1 === 1;  // result is – true (because 1 is equal to 1)

console.log(isvalue);  // result is – true

JavaScript null data type.

In JavaScript program, null data type represents a program variable object value that is intentionally or deliberately absent. Where null data type variable stores an empty or non-existent value.

Characteristics of JavaScript null data type.

  • In any JavaScript program, null data type is explicitly assigned to store the absence of a program variable value.

Example of JavaScript null data type.

let employee = null;

console.log(employee);  // result is – null

// It used to reset variables or indicate an empty state in program

let employeeProfile = null;

JavaScript undefined data type.

Undefined data type in JavaScript program represents a program variable that has been declared in the JavaScript program but has not been assigned or indicated any value yet.

Characteristics of JavaScript undefined data type.

  • The JavaScript program automatically assigns undefined to the variables that have been declared in the current JavaScript program but have not been indicated as any value by default.
  • It is also visible in the JavaScript program when you access any such properties. Which does not exist in the current program, or it is a program function that does not return any value.

Example of JavaScript undefined data type.

let course;

console.log(course);  // result is – undefined because here ‘course’ is declared but not assigned

let student = {};

console.log(student.contact);  // result is – undefined property ‘contact’ does not exist

function info() {

  // here is No return statement, so it implicitly returns undefined data type

}

console.log(info());  // result is – undefined

Symbol in JavaScript.

Symbol type in JavaScript programming was first introduced in ES6, and symbol type is used to create unique identifiers for JavaScript program object properties.

Characteristics of a symbol in JavaScript.

  • Every symbol in JavaScript is guaranteed to be unique, as long as its description is equal.
  • Symbols in JavaScript are mainly used for property keys in objects where uniqueness of data type is required.

Example of a symbol in JavaScript.

const symbolp = Symbol(‘symbol description’);

const symbolq = Symbol(‘symbol description’);

console.log(symbolp === symbolq);  // result is – false symbols are unique even if they have the same description

let obj = {

  [symbolp]: “here is a symbol-based key value preview”

};

console.log(obj[symbolp]);  // result is – here is a symbol-based key value preview

Symbols in JavaScript programs are generally used in meta-programming and creating private properties or methods in objects.

JavaScript BigInt Data Type.

The BigInt data type was introduced in JavaScript programs to manage and control very large program variable integer values, which are regular number data types, are limited to the 64-bit floating-point range, and cannot be previewed.

Features of JavaScript BigInt Data Type.

  • The use of BigInt data type in JavaScript programs is 2^53 – 1 (the largest integer value that can be previewed in JavaScript programs in secure order, it is used to preview large integer values.
  • BigInt data type in JavaScript programs is created by adding n at the end of a number.

Example of JavaScript BigInt Data Type.

let bigNumber = 3124234234797979779797979797977n;

console.log(bigNumber);  // result is – 3124234234797979779797979797977n

let output = bigNumber + 10n;

console.log(output);  // result is – 3124234234797979779797979797977n

Remember, JavaScript programs are not fully compatible with BigInt data type, so mixing BigInt data type in JavaScript program operations generates error.

Summary of JavaScript Primitive Types.

Data TypePrimitive Data Type DescriptionExample
StringString data type used to store Sequence of characters values“Hi, vcanhelpsu!”
NumberUsed to store Numeric value (integer or floating-point) data type both at same time33, 3.14, Infinity
BooleanUsed to store Logical value, either true or false Boolean program valuetrue, false
NullIt Used to store Represents the intentional absence of any object or program valuenull
UndefinedUsed to store Variable declared but not assigned a any value in programundefined
SymbolUsed to store  A unique symbol identifier used as object property keysSymbol(‘description’)
BigIntUsed to store Large integers beyond the Number range4234239898978n

Key points of JavaScript Primitive types String Number Boolean types.

  • String and number are one of the most commonly used primitive data types in any JavaScript program.
  • Boolean logical decisions are made in JavaScript programs, such as these are more helpful in if conditional statements.
  • Null and undefined data types in JavaScript programs represent multiple stages of nullity. .
  • Symbols provide unique property keys in JavaScript programs, especially useful for advanced JavaScript programming use cases.
  • The BigInt data type is used to store and manage large integer values ​​in JavaScript programs that exceed the ordinary numeric limit.

Remember, primitive data types in JavaScript programming are immutable, which means that the value of primitive data types cannot be changed once they are declared.