Introduction to JavaScript

Javascript is used to add interactive functionality to our website

It’s support is built directly into modern web browsers(So we don’t need to download anything)

We can run JavaScript directly into the browser console or as a full.js script connected to an HTML file

It’s a full programming language unlike HTML or CSS and support things such as arrays,loops and general logic

Ultimate aim is to show how we can use JavaScript(DOM) to directly change the HTML or CSS shown on the page

Javascript support three data types

  • String: Grouping of words eg: “Prashant”, ’javascript’
  • Number: Any number eg:1,2,2.5
  • Boolean : Always one of the two word eg: true or false

console.log is used to print words to the console

console.log(“hello world”)
hello world

Operators

JavaScript includes the general math operators

  • Add: +
  • Subtract: -
  • Multiply: *
  • Divide: /
2+3
5
3 -2
1
5 * 4
20
5/4
1.25

Modulus Operator: Shows the remainder after we divide a number

10%3
1

Comments

  • These are lines that are not evaluated when the code runs
  • Can be extremely useful when we are looking back our code we have written earlier or other people who will be looking at our code.

Two types of code comment in javascript

  • Single line comment
//This is a single line comment
  • Multiline comment
/* This is 
a multiline comment */

Variables

Variables are used to assign data to a word then we can use that word within our program instead of the data. In future if the variable value changed we have to change the variable value instead of re-writing the entire program.

Now let’s dissect this program step-by-step

  • var is a JavaScript keyword, which is used to create a new variable for us
  • myName is the variable name and its using camelCase convention
  • = is used to assign whatever next to variable
  • Prashant is the value that is equal to assign to the variable

Variables can hold any data type like strings,numbers,Booleans,arrays,functions and objects.

Prompt : Prompt is a javascript function that will generate a pop-up window that asks the user for input and then it will assign their input to a variable.

Like what you read? Give Prashant Lakhera a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.