javascript few things that you need to know
1. primitive data type
in javascript there are two types of data. one is primitive data other one is object data. here we will discuss primitive data types. there are 6 primitive data types that are
string
number
boolean
undefined
symbol
null.
BigInts
primitive data are store in Stack memory. all primitive data are immutable.
example :
const str = ‘Hello World!’; // string data
const num = 10; // number data
const isIt = true/false; // boolean data
const name = undefined; // undefined data
const name; // this is also undefined data
const value = Symbol(‘hello’); // symbol data
const age = null; // null data
2. Object data types
finally, here we will discuss Objects data types. in objects data types there are 3 data types that are object, array, and function. objects data are store in heap memory. all object's data are mutable.
example:
const greeting = function(){ return “Hello World!”; } // function data
const car = { modal: “BMW X3”, color: “black”, doors: 4} // object data
const colors = [“Red”, “Yellow”, “Green”, “Orange”]; // array data
3. try to catch the error
No matter how good we are at programming, sometimes our code has errors. They may happen because of our mistakes. basically, the code stops running in case of an error, printing the errors to console. but there a syntax. this syntax we can use to catch errors. the syntax is “try…catch”.
first, the code in try {…} to executed. if there were no errors, then the catch will be ignored. if there is any error then the catch will be handling the error.
example:
try {
function(); // if this function exists and works perfectly then the error would not happen
} catch (error) {
console.log(error); // if the before function doesn’t exist and not work perfectly then the error will happen
}
4. notice our Coding Style
coding style is set rules or guidelines used when writing the code for a computer. Following a certain style will help programmers read and understand code, and help to avoid getting errors.
Documentation
Vertical Alignment
Comments
Indentation
Meaningful Identifier Names Consistently Typed
Appropriate use of Typedef
The above items are needed in order to write for the quality code.
5. comment for more readable code.
Programming languages offer an option of leaving notes for yourself or others. The JavaScript comment feature simplifies the production of more readable code. They are easy to write: a JavaScript comment block (also known as the multi-line comment) begins with */ and ends with */, while a single line comment starts with //.
6. call stack: here we will see how a setTimeout function work, First main will be to see the setTimeout function in the stack.it will use web APIs for this and start the timer for a timeout in another loop and wait for it until ends.
7. event queue: complete its timeout period and at the end, it is going to push into the event queue, where are all the queued functions stored.
8. event loop: when the event loop sees that timeout it will check for the stack. if the stack is empty then only it will push that callback into the stack. The browser can see that the stack is empty so it will push that callback. after that it will execute.
9. typeof: typeof is a method. in this method, we check of data type. like we have 5. 5 is a number type data. also, we have “5”. this data is string data because of this equation. otherwise object, function, array data type also we can check data type via typeof method.
example:
console.log(typeof(5)); // number data type.
console.log(typeof(“5”); // string data type
10.cross browser testing: Cross Browser Testing is a test to check that your application works as expected with different browsers. the web application can open in any browser by the user. For example, some users prefer to open Facebook web in Mozilla, but others can be using chrome. for that, we need to ensure that the application will work in all popular browsers so that more people can use it.
That’s It for today. I hope you learned something new today. Any comments or suggestions are welcome.
See you soon :)