1 |
|
2 | var square = function(n) {
|
3 | return (n * n);
|
4 | };
|
5 | console.log(square(10));
|
6 | (function () {try {
|
7 | console.log("In try");
|
8 | throw("In catch");
|
9 | } catch (err) {return (function(err) {
|
10 | return console.log(err);
|
11 | })(err);}})();
|
12 | (typeof(window) === "undefined") ?
|
13 | console.log("Not Running on browser") : console.log("Running on browser");
|
14 | var arr = [1, 2, 3, 4, 5];
|
15 | console.log(arr[2]);
|
16 | (1 !== 2) ?
|
17 | console.log("Nos are not equal") : undefined;
|
18 | (typeof(console) === "object") ?
|
19 | console.log("console is an object") : console.log("console is not an object");
|
20 | (toString.call(console) === "[object Array]") ?
|
21 | console.log("console is an array") : console.log("console is not an array");
|
22 | console.log((10 * 10));
|
23 | var i = 2;
|
24 | console.log((i++ * i++));
|
25 | var _ = require('underscore');
|
26 | Array.prototype.forEach.call([1, 2, 3],function(elem,i,list) {
|
27 | return console.log(elem);
|
28 | });
|
29 | (function(name,email,tel) {
|
30 | console.log(name);
|
31 | return console.log(email);
|
32 | })("John","john@example.com","555-555-5556");
|
33 | (function() {
|
34 | console.log("testing do");
|
35 | return console.log("test again");
|
36 | })();
|
37 | console.log(["Hello1"," world1"].join(''));
|
38 | var link = function(data) {
|
39 | return ["<li><a href=",(data).href,">",(data).text,"</a></li>\n"].join('');
|
40 | };
|
41 | var page = function(title,links) {
|
42 | return ["<!DOCTYPE html>\n<html>\n<head>\n <title>",title,"</title>\n</head>\n<body>\n<ul class='nav'>",Array.prototype.reduce.call(links,function(memo,elem) {
|
43 | return (memo + link(elem));
|
44 | },""),"</ul>\n</body>\n</html>"].join('');
|
45 | };
|
46 | console.log(page("My Home Page",[{href:"/about", text:"About"},
|
47 | {href:"/products", text:"Products"},
|
48 | {href:"/contact", text:"Contact"}]));
|