Javascript important things all developer should learn
Abdur Rahman
Posted on May 6, 2021
6 primitive data types in javascript
Undefined
Null
Number
String
Boolean
Symbol
- Undefined
A variable that has not assigned a value. And hold the value undefined. It is just like null.
var akaid;
console.log(akaid);
- Null
A variable has defined with null value. It is like as undefined. It's store nothing.
var abdurrahmanakaid= null;
var akaid;
console.log(abdurrahmanakaid== city);
console.log(abdurrahmanakaid=== city);
- Number
There is only one number type. There is no specific type for integers. The number can be written with or without a decimal point. It is able to represent floating-point numbers, the number type has three symbolic values: +Infinity, -Infinity, and NaN (not-a-number).
var num1 = 10;
var num2 = 15.5;
var num3 = 20 / +0;
console.log(num3);
var num4 = 20 / -0;
console.log(num4);
- String
A string in JavaScript is a sequence of characters. In JavaScript, strings can be created directly by placing the series of characters between double (") or single (') quotes.
var str1 = "Hello, World!";
var str2 = 'Hi, Welcome to JavaScript Tutorial';
- Boolean
It is logical a entity. A variable can have two values true or false.
var isActive = true;
var isDisabled = false;
- Symbol
New in ECMAScript6. A Symbol is a unique and immutable identifier.
var x = Symbol();
var y = Symbol(10);
var z = Symbol('Hello');
console.log(x);
console.log(y);
console.log(z);
javascript Expression
An expression is any valid set of literals, variables, operators, and expressions that evaluates to a single value. The value may be a number, a string, or a logical value. Conceptually, there are two types of expressions: those that assign a value to a variable, and those that simply have a value
javascript error handling
two main types of error in javascript
When it comes to error handling in JavaScript there are two types of errors you can stumble upon. The first type of error is syntax errors. The second type are runtime errors
1 .Syntax errors
syntax errors are also called parsing errors. This is an error that occurs when the JavaScript parser interprets your code. When one of these errors occurs it only affects the code in the same thread.
- Runtime errors The second type of error is runtime errors. These errors are also called exceptions. These errors occur during the execution of your code when you run it.
JavaScript try and catch
Error handling and try…catch statement
The first tool for error handling is a try...catch statement. there is no parenthesis before the first block, the try block. This try block contains the code you want to try to run.
try {
// some code
}
// Declare function outside try block
function myFunction() {
// do something
}
// Create try block
try {
// And invoke the function inside it
myFunction()
}
Catch
When you do this, try the block will call that function. If your function runs without any errors nothing will happen. If there are some runtime errors? This is where catch block comes into play. The catch block looks similar to try
try {
// Run some code
}
catch(error) { // error is the error object, you can use a different name
}
Posted on May 6, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.