var js code example

Example 1: js variable

var Number = 5;
var String = "Hi!";
var boolen1 = true;
var boolen2 = false;
var array = [11, "Hi!", true];
var object = {age:11, speach:"Hi!", likes_Bananas:true};

Example 2: js variables

// JS Variables
var varExample = "var"; // var is use for variable in js the problem with it that it has complicated scope 
let letExample = "let"; // let is pretty much same as var the only thing which make its more varriable is its variable scope.
const constExample = "const"; // const is use for constant values and this variable scope is sane as let

Example 3: js variables

//Making variables with let:
let numberOfFriends = 1;

//Incrementing:
numberOfFriends += 3; //numberOfFriends is now 4

// Variables with const
const minimumAge = 21; //CANNOT REASSIGN!

//Booleans - true or false values
true;
false;
let isHappy = true;

//Naming Conventions
// Use upper camel-cased names:
let numberOfChickens = 6; //GOOD
// NOT THE JS WAY:
// let number_of_chickens = 6;

Example 4: javascript variable

var user_name = prompt("Please enter your name:", "Type here");
alert("Hello " + user_name);

Example 5: js var

var a;
console.log(a);                // scrive in console "undefined" o "" a seconda del browser usato.
console.log('still going...'); // scrive in console "still going...".

Example 6: var js

var num = 1: