DEV Community

deveshprojectwork
deveshprojectwork

Posted on

JavaScript Cheat Sheet

Variable Declaration
var x = 5;
var y = 10;
var length = 16;

var lastName = "Johnson";

var x = {
firstName: "Bean",
lastName: "Cam"
};

document.getElementById("demo").innerHTML = x + y;
document.getElementById('demo').innerHTML = 'Hello JavaScript';

WRITE AND ALERT
document.write('hello world');
window.alert('Hello World'); or alert('Hello World');

Calling function
myFunction(){
alert('Hello World')
}
<'button onclick="myFunction()">Click me.

function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
<'p id='demo'>


document.getElementById("demo").innerHTML = toCelsius(77);

Array
var cars = ["Saab", "Volvo", "BMW"];
var x = cars[1];
cars.sort()

Top comments (0)