First Code Of Life!!

First Code Of Life!!

Declaring (Creating) JavaScript Variables:

Creating a variable in JavaScript is called "declaring" a variable. We declare a JavaScript variable with the var keyword: var carName; After the declaration, the variable has no value (technically it has the value of undefined ) For Example:

var welcomeMessage "WELCOME APOORV"

Console.log

log() function from console class of node.js is used to display the messages on the console. It prints to standard output with newline. For Example:

console.log("Apoorv Shrimali")

Function in Javascript

A function in JavaScript is similar to a procedure a set of statements that performs a task or calculates a value, it should take some input and return an output where there is some obvious relationship between the input and the output. For Example:

function play(question, answer, options)

If and Else Very often when we write code, we want to perform different actions for different decisions.

We can use conditional statements in our code to do this.

In JavaScript we have the following conditional statements:

Use if to specify a block of code to be executed, if a specified condition is true Use else to specify a block of code to be executed, if the same condition is false

For Example:

if (hour < 18) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}

Loops

Loops are handy, if we want to run the same code over and over again, each time with a different value. For Example:

var carname =['maruti', 'honda', 'tata', 'mahindra']
for (let i=0; i=carname.length; i++){
console.log(carname[i])
}

Enjoy Your Coding!!!!