JS Function, Object, Errors, Coding Style, Cross Browsing……All in one😍
Javascript is a lightweight, interpreted, or just-in-time compiled programming language with the first-class function. It is also a full-fledged dynamic programming language that can interact with a website. It was invented by Brendan Eich.
Primitive Values
=============
- undefined(undefined), used for the unintentionally missy value.
- Null(null), used for intentionally missing values.
- Booleans(true and false), used for logical operations.
- Numbers(-100,3.21416 and others), used for math calculations.
- Strings(“hello”, “America”, and others), used for text.
- Symbols(uncommon), used for hide implementation details.
- BigInts(uncommon and new), used for math on big numbers.
Objects and Functions
==================
- Objects({} and others), used to group related data and code.
- Functions(x => x*2 and others), used to refer to code.
console.log(typeof([])); // “object”
console.log(typeof(new Date())); // “object”
console.log(typeof(/(hello|goodbye)/)); //
“object”
Error Handling, “try…catch”
=====================
Error showing for our mistakes, and unexpected user input, erroneous server response, and for a thousand other reasons.
Normally, a script immediately stops in case of an error, printing it to console.
But try…catch that allows “catch” error so it can do something more reasonable.
try() {
// code…
} catch (err) {
// error handling
};
That means this works in this such way which I describe bellows: If there were no errors, then catch(err) is ignored and skipping the catch with publishing the try() field.
if an error occurs, then the try() execution is stopped and flows to the catch(err). The err variable contains an error object with details.
How to Write Code for JavaScript?
===========================
Our Code must be clean and easy to read as much as possible. That is actually part of programming skill and it also helps to make human-readable. If you are a JavaScript prommer then must follow the undermentioned valuable point for coding:
- Must give a space between parameters.
- No space between the function name and parentheses between the parentheses and the parameter.
- Curly brace { on the same line, after space.
- Indentation 2 space after writing a function.
- Spaces around operators.
- A space after for/if/while...
- After every statement a semicolon is mandatory.
- An empty line between logical blocks.
- Lines are not very long.
- } else { without a line break
- Spaces around a nested call.
- comments single line by //code and multiline /*code */
Cross Browser Testing:
==================
Cross-browser testing is making sure that the websites and web apps created by you which is an acceptance by any web browsers.
The different browser used by people regularly and different devices with different capabilities based websites test are required before publishing your website or Mobile applications.
Remember that developers are not users. Must follow the bellows:
- Test it must be a couple of stable browsers on the system, like Firefox, Safari, Chrome, or IE/Edge.
- Do some lo-fi accessibility testing.
- Test on a mobile platform such as Android or iOS.