In [2]:
var a = 12;
var b = "34";
Out[2]:
undefined
In [3]:
a + b
Out[3]:
'1234'
In [4]:
a - b
Out[4]:
-22
In [13]:
var a = 12;
var b = "12";
if (a===b) {
    console.log("a is equal to b")
}
Out[13]:
undefined
In [16]:
12 === 12.0
Out[16]:
true
In [17]:
var my_list = [12, 10, 15, "Hello"];
Out[17]:
undefined
In [18]:
my_list[0]
Out[18]:
12
In [19]:
my_list[1] = 100
Out[19]:
100
In [20]:
my_list
Out[20]:
[ 12, 100, 15, 'Hello' ]
In [21]:
my_list.push(999)
Out[21]:
5
In [22]:
my_list
Out[22]:
[ 12, 100, 15, 'Hello', 999 ]
In [23]:
delete my_list[2]
Out[23]:
true
In [24]:
my_list
Out[24]:
[ 12, 100, , 'Hello', 999 ]
In [25]:
my_list[2]
Out[25]:
undefined
In [26]:
var my_list = [12, 10, 15, "Hello"];
Out[26]:
undefined
In [27]:
for (i in my_list) {
    console.log(i)
}
0
1
2
3
Out[27]:
undefined
In [28]:
for (i in my_list) {
    console.log(my_list[i])
}
12
10
15
Hello
Out[28]:
undefined
In [29]:
for (i of my_list) {
    console.log(i)
}
12
10
15
Hello
Out[29]:
undefined
In [30]:
my_list.length
Out[30]:
4
In [31]:
var my_dict = {'a': 1, 'b': 100, 'c': 'hello'}
Out[31]:
undefined
In [32]:
my_dict
Out[32]:
{ a: 1, b: 100, c: 'hello' }
In [33]:
var my_dict = {a: 1, b: 100, c: 'hello'}
Out[33]:
undefined
In [34]:
my_dict['a']
Out[34]:
1
In [35]:
my_dict['b']
Out[35]:
100
In [36]:
my_dict.a
Out[36]:
1
In [37]:
my_dict.b
Out[37]:
100
In [38]:
var other_dict = {10: 20, '10': 30}
Out[38]:
undefined
In [39]:
other_dict
Out[39]:
{ '10': 30 }
In [40]:
other_dict['10'] = 100
Out[40]:
100
In [41]:
other_dict
Out[41]:
{ '10': 100 }
In [42]:
other_dict['haha'] = 'hoho'
Out[42]:
'hoho'
In [43]:
other_dict
Out[43]:
{ '10': 100, haha: 'hoho' }
In [44]:
other_dict.haha
Out[44]:
'hoho'
In [60]:
var a = [1, 2, 10];
var b = [0, 1];
Out[60]:
undefined
In [64]:
c = a.concat(b)
Out[64]:
[ 1, 2, 10, 0, 1 ]
In [66]:
c.push(1, 2, 10)
Out[66]:
8
In [68]:
c.push([10, 20])
Out[68]:
9
In [72]:
c
Out[72]:
[ 1, 2, 10, 0, 1, 1, 2, 10, [ 10, 20 ] ]
In [71]:
c.slice(1, 3)
Out[71]:
[ 2, 10 ]
In [62]:
a.toString()
Out[62]:
'1,2,10'
In [57]:
b.toString()
Out[57]:
'0,1'
In [88]:
function hello(name) {
    var x = 2;
    console.log(x);
    console.log("Hello " + name);
    return x * 2;
}
Out[88]:
undefined
In [93]:
var x = 10;
hello("Harry");
console.log(x);
2
Hello Harry
10
Out[93]:
undefined
In [91]:
y = hello("Harry")
2
Hello Harry
Out[91]:
4
In [92]:
y
Out[92]:
4
In [94]:
10;
15;
Out[94]:
15
In [105]:
function sum(some_list) {
    var s = 0;
    for (var element of some_list) {
        s = s + element;
    }
    return s;
}
Out[105]:
undefined
In [106]:
x = sum([1, 2, 10])
Out[106]:
13
In [107]:
x
Out[107]:
13
In [104]:
element = 1
sum([1, 2, 15])
console.log(element)
1
Out[104]:
undefined
In [108]:
function sum(some_list) {
    var s = 0;
    for (var i in some_list) {
        s = s + some_list[i];
    }
    return s;
}
Out[108]:
undefined
In [110]:
function sum(some_list) {
    var s = 0;
    for (var i=0; i<some_list.length; i++) {
        s = s + some_list[i];
    }
    return s;
}
Out[110]:
undefined
In [123]:
my_list = [1, 2, 10]
Out[123]:
[ 1, 2, 10 ]
In [130]:
my_list[10]
Out[130]:
undefined
In [125]:
my_list.length
Out[125]:
3
In [132]:
my_list[10] = 99
Out[132]:
99
In [133]:
my_list
Out[133]:
[ 1, 2, 10, , , , , , , , 99 ]
In [137]:
my_list[4]
Out[137]:
undefined
In [111]:
sum([12, 100, 54])
Out[111]:
166
In [ ]:
function sum(some_list) {
    var s = 0;
    var i=0
    while (i<some_list.length){
        s = s + some_list[i];
        i++;
    }
    return s;
}