Revisiting JavaScript With Sagar Jaybhay

Revisiting JavaScript By Sagar Jaybhay

Uses of JavaScript

  1. Client-side validation: by using this application much more responsive and no need for the round trip on server.ex. Form-Validation by using client-side validation we reduce the round trips on a server which means we reduce the load on the server.
  2. To run the code JavaScript uses client machine processing power.
  3. With JavaScript, partial page updates are also possible without reloading an entire web form
  4. For animation also we can use JavaScript.

Disadvantages of JavaScript

  1. Security: JavaScript runs on the client machine so hacker may use JavaScript to do a variety of things like tracking your browser history, stealing your password.
  2. Browser Compatibility: For the same piece of JavaScript code may be treated differently by a different browser. Example: innerText is supported by Chrome and IE but not Firefox.
  3. Code Always Visible: The biggest disadvantages is code always visible to everyone anyone can view JavaScript code.
  4. Stop Render: JavaScript single error can stop to render with the entire site. However, browsers are extremely tolerant of JavaScript errors.
  5. Disable JavaScript: If you disable JavaScript in the browser, the entire JavaScript code is not run.
  6. File Download: JavaScript file is download on the client machine so anyone can read the code and reuse it.

Where should we put <script></script> tag in Html?

The script tag should be placed in body or head section of Html page and in general <script> tag can be placed in the body of Html.

If you placed <script> tag in head section of Html page then if your controls not loaded till now then your code might not work.

Also another reason is that if you refer external JavaScript file and you refer this in head section so web browser not start their parsing of web-page till the external file completely download.

It is better to place the <script> tag near closing body tag.

Is JavaScript case sensitive language?

Yes JavaScript is case sensitive language. Variable names, keywords, methods and object properties, and event handlers these all are case sensitive

console.log('Hello Sagar Jaybhay');
//output  Hello Sagar Jaybhay

It id different from this below code

console.Log('Hello Sagar Jaybhay');

The output of this code is

TypeError: console.Log is not a function

Different methods to convert string to number in JavaScript.

parseInt in JavaScript

This is inbuilt method in JavaScript by which we can convert string to number.

var a="10";
var b="20";
c=parseInt(a)+parseInt(b);
console.log(c)

parseFloat In JavaScript

By using this method you not lose decimal places so whenever needed use this parsefloat

var a="10.2";
var b="20.3";
c=parseFloat(a)+parseFloat(b);
console.log(c)

NaN In JavaScript

In JavaScript NaN stands for Not-a-Number. In JavaScript we have isNan() function which determines whether a value is illegal number or not. It will return value true if string is not valid number else it will return false.

var a="sagar"
console.log(isNaN(a)) //true

var b=10
console.log(isNaN(b)) //false

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *