10 JavaScript Concepts you must know as a JavaScript programmer.

JavaScript Concepts

Error Handling………

Overview :

* Types of Errors

1) Try…..Catch

//Syntaxtry {  
// code...
} catch (err) {
// error handling
try{alert('Hello world');alert(students); 
// here handle an error, because here student is string, we didn't use quotation or we didn't declare it before use. Notice that, here our programs never stops for this error, program will be executed.
alert('is it working properly?') }catch{alert('contains errors')}

2) try…finally

The finally-block will always execute after the try-block and catch-block() have finished executing. It always executes, regardless of whether an exception was thrown or caught.

//Syntaxtry {
tryCode - Block of code to try
catch(err) {
catchCode - Block of code to handle errors
finally {
finallyCode - Block of code to be executed regardless of the try / catch result
//examplevar count = 0;
function foo() {
try {
return count;
} finally {
// expected output: 0

3) try…catch…finally

You can also use the try…catch…finally statement to handle exceptions. The finally block executes both when the code runs successfully or if an error occurs.

//Syntaxtry {
// try_statements
catch(error) {
// catch_statements
finally() {
// codes that gets executed anyway
//exampleconst numerator= 100, denominator = 'a';

try {
}catch(error) {
console.log('An error caught');
console.log('Error message: ' + error);
}finally {
console.log('Finally will execute every time');
// expected output:NaN
An error caught
Error message: ReferenceError: a is not defined
Finally will execute every time

4) Comments

We should to keeps our coding clean & easy so that anyone can read our understand ours coding. For this we can use comments, So that everyone understands which line we are using for which work.

//example// this is single line comments /** this is multiple line comments-1
*this is multiple line comments-2
*this is multiple line comments-3
*this is multiple line comments-4

5) Block Bindings

Traditionally, the way variable declarations work has been one tricky part of programming in JavaScript. In most C-based languages, variables (or bindings) are created at the spot where the declaration occurs. In JavaScript, however, this is not the case. Where your variables are actually created depends on how you declare them, and ECMAScript 6 offers options to make controlling scope easier. This chapter demonstrates why classic var declarations can be confusing, introduces block-level bindings in ECMAScript 6, and then offers some best practices for using them.

6) Var Declarations and Hoisting

//examplefunction student(name) {
console.log("Student Name:" + name);
catName("Fayez");// expected output:Student Name: Fayez

Frontend Developer