Some Javascript Concepts
There are two data types in JavaScript which are primitive and non-primitive.
1.Primitive Types: Primitive values are stored as single data values like numbers and strings.
Ex :
console.log(5);
console.log(“Milton”);
console.log(undefined);
2. Non-Primitive Types: It is storing a collection of data objects and can say store the reference of the data values is called non-primitive type data. Object and function are two of non-primitive type data.
console.log({});
console.log([]);
console.log(x => x * 2);
3. Expressions :
An expression is any valid unit of code that shows the output as a single value.
Let’s say 3 + 4 is an example of an expression type. This expression uses the ‘+’ operator to add operand three and four together without assigning the result, shows output seven as a single value.
4.Try-Catch:
It is for handling the runtime error.
Ex :
try { “works if all are fine”}
catch (err) {
alert(“The engine can’t understand this code, it’s invalid”);
}
5. Function with default parameters
In JavaScript, the default parameter is set to undefined. It allows named parameters to be initialized with any default values if no value has passed undefined is set.
6. Arrow Function: An arrow functions another type of traditional function we use.
But, It is limited to use.
Ex :
const profile = [
Name: “Milton”
Id: 25
Designation: “Programmer”
];
console.log(profile.map(element => element.length));
Output : 3
7. Block Statement: Statements grouped within the block or any curly braces are called block statements.
Ex : {
Statement …
}
8. Checking types: There are Seven data types in JavaScript. As It’s not typed strict, we can able to check the type of a variable by using typeof Operator.
const x = 'Milton'
console.log(typeof x)
// Output : "string"
const y = 12
console.log(typeof x)
// Output : "number"
9. Spread Operator: Spread operator makes developer’s life easy. It used to copy any object or array into another object or array. Simply, we have to place 3dots before any array or object to copy it to another array or object.
10. Comments: A comment is something that can be kept off the various lines within the code. With this comment, we can write our important things next to the quote which will help us to understand the code later.
- Single line comment:
//Write something
console.log(“Hello world”) //Expected output: Hello world
2. Multi-line comment:
/*
Write something
Your important notes
*/
console.log(“Hello world”) //Expected output: Hello world