JavaScript Basics

JavaScript Basics

In this video we will discuss br 1. Is JavaScript case sensitive br 2. Comments in JavaScript br 3. Data types in JavaScript br br Is JavaScript case sensitive br Yes, JavaScript is case sensitive programming language. Variable names, keywords, methods, object properties and event handlers all are case sensitive. br br Example 1 : alert() function name should be all small letters br br alert("JavaScripts Basics Tutorial"); br br br Example 2 : Alert() is not same as alert(). Throws Alert is not defined error. To see the error press F12 key. br br Alert("JavaScripts Basics Tutorial"); br br br Comments in JavaScript : There are 2 types of comments in JavaScript. br 1) Single Line Comment br br Example : br br This is a sinle line comment br br br 2) Multi Line Comment br br Example: br br * This is a br multi line br comment * br br br Data types in JavaScript br br The following are the different data types in JavaScript br Numbers - 5, 5.234 br Boolean - true false br String - "MyString", 'MyString' br br To create a variable in JavaScript use var keyword. Variable names are case sensitive. br br In c# to create an integer variable we use int keyword br int X = 10; br br to create a string variable we use string keyword br string str = "Hello" br br With JavaScript we always use var keyword to create any type of variable. Based on the value assigned the type of the variable is inferred. br var a = 10; br var b = "MyString"; br br In C#, you cannot assign a string value to an integer variable br int X = 10; br X = "Hello"; Compiler error br br JavaScript is a dynamically typed language. This means JavaScript data types are converted automatically as needed during script execution. Notice that, in myVariable we are first storing a number and then a string later. br br var myVariable = 100; br alert(myVariable); br myVariable = "Assigning a string value"; br alert(myVariable); br br br When a + operator is used with 2 numbers, JavaScripts adds those numbers. br br var a = 10; br var b = 20; br var c = a + b; br alert(c); br br br Output : 30 br br When a + operator is used with 2 strings, JavaScript concatenates those 2 strings br br var a = "Hello " br var b = "JavaScript"; br var c = a + b; br alert(c); br br br Output : Hello JavaScript br br When a + operator is used with a string and a number, JavaScript converts the numeric value to a string and performs concatenation.


User: Kudvenkat

Views: 9

Uploaded: 2014-11-16

Duration: 07:58

Your Page Title