Table of Contents
It Is Recommended to Use 3 Equal Signs Instead of Two Equal Signs
This guide provides a clear overview of javascript, including It Is Recommended to Use 3 Equal Signs Instead of Two Equal Signs, Use SET to Get Unique Values. Use it to understand the topic, compare the available options, and make a more informed decision.
// là false, vì nó ki?m tra ki?u d? li?u c?a c? LHS và RHS [1] === 1 // true, vì nó typecasts giá tr? bên trái, là 1, b?ng RHS. [1] == 1 // false, vì LHS là m?t ký t? còn RHS là s? nguyên. '2' === 2 // true, do typecasting. '2' == 2 'undefined'=='undefined' // true 'undefined' === 'undefined' // true 0 == false // true 0 === false // false
Use SET to Get Unique Values
In an array provided in JavaScript (ES6 version), if we are copying values inside it, and want to have all unique values, store this array in a specified SET object. introduced in version ES6.
// arr là array trùng l?p m?ng s? nguyên Const arr = [10,10,20,20,30]; = [10,10,20,20,30]; // L? tr? m?ng trên trong new_arr const new_arr = [.new Set(arr)]; // Print new_arr console.log(new_arr); // Result: [10, 20, 30]
Result:[10, 20, 30]
Without Set, this process will be time consuming. You have to iterate through the array and store the unique elements one after another in a new object.
Direct Manipulation in Console.log)
You can directly perform operations on console.log() itself. You do not need to calculate before printing to the console. It can perform Add, Subtract, Multiply, Divide, Power, Increment, Decrement and logic operations on its panel.
var a = 10; var b = 20; // Phép c?ng console.log("Addition of a and b: " + (a + b) ); // Phép tr? console.log("Subtraction: " + (a - b) ); // Phép nhân console.log("Multiplication between a and b: " + (a * b) ); // Phép chia console.log("The Quotient will be: " + (b / a) ); // Modulo, khi a chia cho b console.log((a % b)); // pre-increment console.log("Value of a after pre-increment: " + (++a) ); // post-increment console.log("Value of a after post-increment: " + (a++) ); // pre-decrement console.log("Value of b after pre-decrement: " + (--b) ); // post-decrement console.log("Value of b after post-decrement: " + (b--) ); // L?y th?a console.log("2 raise to the power 3: " + (2**3);
Reduce the Length of an Array
You can reduce the length of an array using the function ( array.length).
Suppose, there is an array of size 10. And you need the first element k in it, (k < 10) of the array, You can reduce the length of the array to get the array of reduced size as you want.
For example:
Array: [ 11, 12, 122, 133, 152], size= 4;
Here we need an array of 2. So that array will be [ 11,12 ].
var array = [1, 2, 5, 78, 98] console.log("The array of size ",array.length) // kích th??c c?a m?ng là 4 array.length=4; console.log("The array of size ", array.length,"is :",array) // kích th??c c?a m?ng là 3 array.length=3; console.log("The array of size ", array.length,"is :",array) //kích th??c c?a m?ng là 2 array.length=2; console.log("The array of size ", array.length,"is :",array)
Use Slice to Get Selected Elements in an Array
The Slice method is used in arrays to get selected elements from an array. It returns a new array containing the selected elements, but the original array is left untouched.
Syntax:array.slice(start, end)
Above are some useful JavaScript programming tips for programmers. Hope the article is useful to you.
Conclusion
Understanding Javascript makes it easier to compare options, avoid common mistakes, and apply the information in this guide more effectively. Review the relevant requirements before making changes or choosing a solution.
FAQ
What is Javascript?
It Is Recommended to Use 3 Equal Signs Instead of Two Equal Signs This guide provides a clear overview of javascript, including It Is Recommended to Use 3 Equal Signs Instead of Two Equal Signs, Use SET to Get Unique Values.
Why is Javascript important?
Understanding Javascript helps you evaluate features, compatibility, performance, and potential limitations before you choose a product or follow a procedure.
What should you consider when using or choosing Javascript?
Consider your specific goal, compatibility requirements, available features, cost, security, and the practical recommendations described in this guide.
Reader Comments 0
Sign in with email or Google to join the discussion.