JavaScript
- console.time();
- console.timeEnd();
- console.table();
- console.clear();
- console.error();
- console.assert();
console.assert(12 < 11 "true");
Variables and Data Types
Rules of defining Variables:
- Variables can not start with numbers.
- Variable can start with the letter, underscore("_").
- Note: JavaScript is a case-sensitive language.
Most common programming case type:
- camelCase
- Kebab-case
- snake_case
- PascalCase
- camelCase
- Kebab-case
- snake_case
- PascalCase
Data Types
- Primitive data type
- Reference data type
- Primitive data type
- Reference data type
Primitive data type:
- The primitive data type is known as the Built-in data type in JavaScript.
- The memory location of primitive data type in a stack.
- base
Examples:
- String
- numbers
- Boolean
- Null
- undefined
- symbol (ES6 classes)
- The primitive data type is known as the Built-in data type in JavaScript.
- The memory location of primitive data type in a stack.
- base
Examples:
- String
- numbers
- Boolean
- Null
- undefined
- symbol (ES6 classes)
Reference data type
- The primitive data type is known as the User-defined data type in JavaScript.
- The memory location of reference data type in a Heap.
- Object
Examples:
- Array
- Object literals (like dictionary)
- functions
- dates
- The primitive data type is known as the User-defined data type in JavaScript.
- The memory location of reference data type in a Heap.
- Object
Examples:
- Array
- Object literals (like dictionary)
- functions
- dates
Type conversation
Code snippet:
let a = String(45);
//OR
//a = '45';
console.log(a);
//To find the type of the variable
console.log(typeof a);
//Is use to convert the variable into a string
console.log(a.toString());
let a = 45;
let b = a.toString();
console.log(typeof a);
console.log(typeof b);
let a = Number("45");
// a = Number("45fgjhf");
let b = a.toString();
console.log(typeof a);
console.log(typeof b);
console.log(a, b);
let a = Number(true);
let b = a.toString();
console.log(typeof a, a);
console.log(typeof b, b);
let a = parseInt('45');
console.log(typeof a);
console.log(a);
//convert onto integer
let a = parseInt('45.4567');
console.log(typeof a);
console.log(a);
//Convert into float
let a = parseFloat('45.4567');
console.log(typeof a);
console.log(a);
//Is use to fix the decimal zero position
console.log(a.toFixed());
console.log(a);
//Is use to fix the decimal second position
console.log(a.toFixed(2));
console.log(a);
//concatination
console.log("3"+2);
Comments
Example:
//This is singel line comment
/*
This is multiline comment
*/
Strings
Strings are useful for holding data that can be represented in text form.
- Properties, Methods, and Template Literals:
String Methods:
- startsWith():
- endsWith():
- includes():
- split():
- length()
- slice()
- substring()
- substr()
- replace()
- replaceAll()
- toUpperCase()
- toLowerCase()
- concat()
- trim()
- trimStart()
- trimEnd()
- padStart()
- padEnd()
- charAt()
- charCodeAt()
- indexOf()
- lastIndexOf()
- search()
- match()
- matchAll()
String Literals:
let text = "Hello world!";
0 Comments